Archive for October 26, 2018

Friday, October 26, 2018

Flattening Nested Optionals Resulting From try?

SE-230:

Swift’s try? statement currently makes it easy to introduce a nested optional. Nested optionals are difficult for users to reason about, and Swift tries to avoid producing them in other common cases.

This document proposes giving try? the same optional-flattening behavior found in other common Swift features, to avoid the common occurrence of a nested optional.

John McCall:

How important is this problem to fix? It arises from a combination of two things: using the try? operator on a result that is already optional. This is, perhaps, not very common; it probably reflects two different methods of failure being used in one expression. But when it does happen, the extra optionality is almost always unwanted and causes significant friction for the programmer, demanding awkward workarounds: code like try? foo() has to be turned into something like (try? foo()) as? T. By forcing programmers to deal with the awkwardness of nested optionals more often, it raises the overall perceived complexity of working with optionals in Swift, and it makes try? feel unintuitive.

The Core Team does not want to make source-incompatible changes lightly, but we also want to leave room to improve the language for future users of Swift. We don’t have a bright-line rule for when a change crosses the line to become unacceptable, but the key consideration in our analysis is the change’s apparent impact in practice on existing code more than its hypothetical risks. In this case, we are convinced that the change leads to fairly inarguably better results.

I concur.

John McCall:

Casting doesn’t really “flatten”; it looks for any way in which it can interpret the operand value as the target type, and then wraps in a level of optionality to represent that that search can fail. But it’ll happily look through protocol types and so on. Any static behavior is going to seem inconsistent compared to that if you think of it as flattening, including the current behavior of try?.

Mysterious Reduced iPhone Battery Life

I’m not sure what’s changed other than iOS 12, but my iPhone’s battery is draining like never before. It can now drop from 100% to 50% sitting on my nightstand overnight. I thought maybe an app was doing something in the background, but the Battery area of Settings shows no activity whatsoever during that time.

And, for many years, I’ve been taking my iPhone on day hikes and recording a GPS track with MotionX-GPS. I carry an external Jackery battery just in case, but the internal one usually lasts the whole day, six hours or so of camera and background GPS use. No longer. On my last two hikes, the battery drained to zero in under an hour. The Battery screen simply shows that MotionX-GPS was running; nothing looks out of the ordinary.

The Battery Health display shows that Maximum Capacity is still 100% on this 18-month-old iPhone SE, although it notes that performance management has been applied due to an unexpected shutdown.

Previously: Battery Health and Peak Performance Capacity.

Update (2018-10-29): Rob Mathers:

My SE started draining more heavily earlier this year. Not to the extent of yours, but still bad. I got the battery replaced, with small improvements, but eventually caved and went to the XS, which is way better.

I do still wonder what changed…

Jeff Baxendale:

My 6s battery is at 88% max capacity (replaced last year for free) and says the performance throttling has been applied.

I’ve (+ my fam) generally noticed it draining faster too… trying to see what is doing it, but also hard to argue with how much more responsive the OS feels.

I’ve found that disabling Screen Time helped a lot. My iPhone is now at 75-80% in the morning (still lower than with iOS 11). I’ve also noticed that turning Screen Time on makes the battery start draining quickly. I also tried turning off Compass Calibration, but that didn’t seem to make a difference.

Apple on the “Radical” Use of Humans to Edit the News

Chrysanthe Tenentes:

This is an interesting look at how Apple News approaches curating their product, which reaches 90 million people. Unlike other algorithm-focused Silicon Valley giants, Apple uses human editors to surface news stories. They layer those hand-picked stories, some of which will get a million views each, with trending and topic-based stories via algorithm.

Apple (surprisingly) gave access to their News editor in chief, Lauren Kern, who weighs accuracy above speed.

Mitchel Broussard:

Some publishers remain concerned with Apple News’ future, particularly because of Apple’s ad revenue policies. For one, readers on Apple News stay inside of Apple’s app for the most part, curbing ad revenue for the publisher of the article and limiting data from direct clicks to the sites. While publishers can sell ads on their stories in Apple News, most say the process is complicated and that advertiser interest was low because of the lack of consumer data.

Apps Can Track You Even After You Uninstall Them

Gerrit De Vynck:

Uninstall tracking exploits a core element of Apple Inc.’s and Google’s mobile operating systems: push notifications. Developers have always been able to use so-called silent push notifications to ping installed apps at regular intervals without alerting the user—to refresh an inbox or social media feed while the app is running in the background, for example. But if the app doesn’t ping the developer back, the app is logged as uninstalled, and the uninstall tracking tools add those changes to the file associated with the given mobile device’s unique advertising ID, details that make it easy to identify just who’s holding the phone and advertise the app to them wherever they go.

The tools violate Apple and Google policies against using silent push notifications to build advertising audiences, says Alex Austin, CEO of Branch Metrics Inc., which makes software for developers but chose not to create an uninstall tracker. “It’s just generally sketchy to track people around the internet after they’ve opted out of using your product,” he says, adding that he expects Apple and Google to crack down on the practice soon. Apple and Google didn’t respond to requests for comment.

Previously: Push Notifications to Send Promotions.

Update (2018-11-06): Tanner Bennett:

I got fed up with this the other day. There’s all sorts of public APIs, few of which should be public imo, that allow companies to fingerprint devices.

To name a few, apps can see your connected WiFi SSID, the name of your device (“Tanner’s iPhone”), and the device model.

It was fun writing a tweak to randomize all of these and see which apps broke because of it.

Custom Icons for Quick Actions

Matthias Gansrigler:

The trick is to have the file end in ‘Template’, like ‘MyWorkflowIconTemplate.tiff’. But that’s not all there is to it. When you add a custom icon through Automator, it automatically gets renamed into ‘workflowCustomImage.png’. So no matter what you name your file, it won’t matter.

To fix this, add a custom icon to your Quick Action in Automator, save, switch to Finder and navigate to /Users/yourname/Library/Services/, where your newly saved Quick Action will end up. There, right-click your Quick Action, select ‘Show Package Contents’, and navigate into Resources, where your icon file will be. Rename it to ‘workflowCustomImageTemplate.png’. Now, navigate into Contents and open Info.plist. Look for <key>NSIconName</key> and change ‘workflowCustomImage’ to ‘workflowCustomImageTemplate’. Save.

You can use Quick Actions with both DropDMG and EagleFiler. The main catch, from my perspective, is that Finder accepts click-through for them. So if you have a habit of bringing Finder windows to the front by clicking near the bottom-right, be aware that you may accidentally invoke a Quick Action.

Gansrigler also has a tip for making the right kind of TIFF file for the Touch Bar. However, you don’t have to write code to do this. You can make a multi-representation TIFF using tiffutil.

The Problem with Facebook and Virtual Reality

Ben Thompson:

Anything made by Facebook is necessarily biased towards being accessible by everyone, which is a problem when creating a new market. Before technology is mature integrated products advance more rapidly, and can be sold at a premium; it follows that market makers are more likely to have hardware-based business models that segment the market, not service-based ones that try and reach everyone.

To that end, it is hard to not feel optimistic about Apple’s chances at eventually surpassing Oculus and everyone else. The best way to think about Apple has always been as a personal computer company; the only difference over time is that computers have grown ever more personal, moving from the desk to the lap to the pocket and today to the wrist (and ears). The face is a logical next step, and no company has proven itself better at the sort of hardware engineering necessary to make it happen.

Critically, Apple also has the right business model: it can sell barely good-enough devices at a premium to a userbase that will buy simply because it is from Apple, and from there figure out a use case without the need to reach everyone.