Archive for March 25, 2016

Friday, March 25, 2016

Surprises With Swift Extensions

Peter Steinberger:

These seemingly innocent extensions were overriding private API. Apple’s private API detection is not super sophisticated and wasn’t triggered when the app was uploaded to the App Store. It’s also not a public symbol so there were no warnings, not even a log message. Unprefixed categories are always dangerous, especially on classes that you do not own, like UIViewController. In PSPDFKit, we use categories for shared code, but prefix any method with pspdf_ to be absolutely sure we do not hit any name clashes. It’s certainly not pretty, and prefixes in Swift look even more alien, yet as you can see in this bug hunt, they are definitely necessary.

[…]

You can use @objc(prefix_name) to keep the name pretty in Swift and expose a prefixed version for the ObjC runtime.

Names That Break Computers

Chris Baraniuk (via Rosyna Keller, comments):

“We moved almost immediately after we got married so it came up practically as soon as I changed my name, buying plane tickets,” she says. When Jennifer Null tries to buy a plane ticket, she gets an error message on most websites. The site will say she has left the surname field blank and ask her to try again.

[…]

Some individuals only have a single name, not a forename and surname. Others have surnames that are just one letter. Problems with such names have been reported before. Consider also the experiences of Janice Keihanaikukauakahihulihe'ekahaunaele, a Hawaiian woman who complained that state ID cards should allow citizens to display surnames even as long as hers – which is 36 characters in total.

[…]

But McKenzie is living proof of the fact that name headaches are a relativistic problem. To many English-speaking westerners, the name “Patrick McKenzie” might not seem primed to cause errors, but where McKenzie lives – Japan – it has created all kinds of issues for him.

See also: xkcd and Explain xkcd.

Previously: Falsehoods Programmers Believe.

To Optional or Not to Optional: IBOutlet

Curtis Herbert:

UIKit was written during the era of nil messaging, and I’ve come to realize it isn’t safe to 100% assume IBOutlets can’t be nil. Going forward I’ll be using optionals for my IBOutlets. I have a task in my bug tracker to scrub all my IBOutlets to covert them from implicitly unwrapped to standard optionals. A few extra question marks never hurt anyone; I’d rather my app not crash.

Update (2016-03-30): Scott Berrevoets:

Applying these three rules means you properly use the optional semantics.

ColorSync Support in iOS 9.3

Jeff Carlson:

Apple’s screens are generally very good, but for photographers and other visual artists and designers, the inability to adjust the color profile has meant that the iPad is excluded from any serious image-processing workflows.

Now, with true color management possible on the iPad Pro, the tablet may find a place in that chain, and perhaps photographers will be able to do final adjustment work on an iPad instead of bringing a laptop.