Archive for April 9, 2019

Tuesday, April 9, 2019

Implementing [NSCell copyWithZone:] in Swift to Avoid Crashes in AppKit

Corbin Dunn (tweet):

It looks like using a baseline constraint with Autolayout will cause it to copy the cell to determine the baseline. So, if you are using AutoLayout, be aware of implicit copies that might happen behind your back!

The trouble with [NSCell copyWithZone:] is that it uses NSCopyObject, which blindly assigns ivars from one instance to another and doesn’t do any proper memory management. I didn’t think this would still be an issue in Swift, but apparently it is! See my solution at the top where I simply retain the value during the copy.

He writes:

let _ = Unmanaged<NSColor>.passRetained(previousTextColor)

Toggle System Grayscale Mode

Daniel Jalkut:

The framework name “UniversalAccess” correlates strongly with the “UA” prefix on the pertinent function names we dug up above. Great, so how do we call these? They’re private system functions which means you should not rely on them for production code, but for a quick hack to make toggling grayscale easier? It’s a reasonable risk in my opinion. Here’s a simple C program that takes advantage of the private methods to simply toggle grayscale mode on or off, depending on the current setting.

This is arguably more reliable than using GUI scripting, and definitely faster and less intrusive. Or, if you don’t want use a compiler:

This script takes advantage of Python’s ability to dynamically load an arbitrary shared library and invoke its exported functions.

Update (2019-04-10): Marco Arment:

I love this kind of power and customization, and it’s the kind of thing we’re losing with the dominance of iOS itself and the invasion of the iOS mindset into macOS

Apple Drops $99 Data Migration Fee for New Macs and Repairs

Adam Engst:

Apple has dropped the $99 fee that it previously charged for migrating data from an old Mac to a newly purchased machine. TidBITS reader and TekBasics consultant David Price wrote to tell us that he has generally advised clients to pay Apple to migrate data to newly purchased Macs, but when he accompanied his brother-in-law to pick up a freshly migrated iMac last week, Apple informed him that there was no charge for the service.

Update (2019-04-10): Thomas Brand:

There was never a charge in 2003. We used to even transfer data from booting Windows PCs.

How to Get Bugs Fixed by Apple

Greg Scown:

For example, I received an email with a fractional street address, and Mail’s data detector chopped off the whole number portion of the address. Rather than report the bug with steps in Mail, I figured that the data detector itself was broken and made a very small Xcode Playground to demonstrate the problem. It’s time-consuming to create reductive cases, but it also reduces the likelihood of confusion. Consider that the person reading and reproducing your bug needs to see it as simply as possible.

If there’s no action on your bug, the next step is to mail and request status. Note that it can take a while to get a reply. Filing and following up on getting bugs fixed with Apple is a process, as with anything else.

Previously: The Sad State of Logging Bugs for Apple.

New WebKit Features in Safari 12.1

Jon Davis (Hacker News):

With users’ ability to choose between light and dark color schemes, websites can start to look out of place, or worse, become a blinding and painful experience. To help websites better integrate with the dark appearance setting in macOS Mojave, WebKit provides the supported-color-schemes property and prefers-color-scheme media query to allow a webpage to support light and dark color schemes.

Web content authors can use the @media(prefers-color-scheme: dark) media query to provide dark mode styles that override a default light theme. Alternatively, @media(prefers-color-scheme: light) can be used to provide light styles that override a default dark theme.


The Payment Request API has been updated with granular errors, support for default addresses and contacts configured in Wallet and Apple Pay settings, and special field support for Japan. These changes now bring the Payment Request API to parity with the Apple Pay JS payment system, but with all of the benefits of web standards compatibility. Payment Request is now the recommended way to pay implement Apple Pay on the web.


The Web Share API adds navigator.share(), a promise-based API developers can use to invoke a native sharing dialog provided the host operating system. This allows users to share text, links, and other content to an arbitrary destination of their choice, such as apps or contacts.


Another newly supported element in WebKit is the <datalist> element. The <datalist> element contains a list of <option> elements that provides suggested values for <input> elements.

Previously: Dark Side of the Mac: Appearance & Materials.