Archive for July 31, 2018

Tuesday, July 31, 2018

Objective-C Features That I Wish Existed

Daniel Lazarenko (via Gianluca Bertani):

The features listed here are chosen to have a relatively small scope in order to be implemented without major changes and in a backwards compatible way in the spirit of Objective-C. Thus they are not meant to turn Objective-C into a modern experimental language like Swift, but should make programming experience better and reduce boilerplate.


In 2015 Xcode 6.3 introduced nullability annotations to Objective-C. With those you can express an intent that a pointer to an object can never be nil. Unfortunately the only observable check that the Objective-C compiler does with that is that it prevents you from passing the nil constant in places where a nonnull type is expected. If you pass in a nullable pointer variable (not a nil constant), this is silently allowed[…]


Imagine a piece of code that uses a lot of blocks, including nested blocks where on completion you want to do something else asynchronously, so you have to make a second strongSelf. This pattern becomes boilerplate code! It is possible to shrink the lines by using @weakify/@strongify custom helper macros, but you still have to write them and have them available in your project.

Update (2018-08-02): Heath Borders:

If you use -Wnullable-to-nonnull-conversion and nullability annotations on local variables and properties, you get proper warnings when you pass a _Nullable to a _Nonnull parameter or assign a _Nullable rvalue to a _Nonnull lvalue.

And if you ever need to cast a _Nullable to a _Nonnull, this is the safe way to do so.

Please Follow in Apple News

Adam Engst:

Apple News is focused on large publishers and therefore needs quite a number of articles for training its natural language parser. Since we publish only about 50 articles per month, whereas a large publisher might release several times that per day, I was told that it could take several months before the algorithm knew what to do with our content.


Most notably, I was told that Apple News cares quite deeply about the number of people who follow a particular publication—the more followers, the more likely Apple News is to recommend that publication’s articles to other people.


However, Apple subsequently told me that the Apple News algorithm also takes some of its cues from those [section] names, so I’ve added more sections that match up with topic names (Apple, Mac, iOS, Cybersecurity, and so on) that people can find in Apple News when searching for specific topics of interest.

You can follow this blog on Apple News here.

Previously: Switching From RSS to Apple News Format.

The Swift Compiler Can Reason About “Never”

Mattt Thompson:

By specifying Never as the result’s Error type, we’re using the type system to signal that failure is not an option. What’s really cool about this is that Swift is smart enough to know that you don’t need to handle .failure for the switch statement to be exhaustive:

alwaysSucceeds { (result) in
    switch result {
    case .success(let string):

You can see this effect played out to its logical extreme in the implementation conforming Never to Comparable:

extension Never: Comparable {
  public static func < (lhs: Never, rhs: Never) -> Bool {
    switch (lhs, rhs) {}

The Bullshit Web

Nick Heer (Hacker News):

The average internet connection in the United States is about six times as fast as it was just ten years ago, but instead of making it faster to browse the same types of websites, we’re simply occupying that extra bandwidth with more stuff. Some of this stuff is amazing: in 2006, Apple added movies to the iTunes Store that were 640 × 480 pixels, but you can now stream movies in HD resolution and (pretend) 4K. These much higher speeds also allow us to see more detailed photos, and that’s very nice.

But a lot of the stuff we’re seeing is a pile-up of garbage on seemingly every major website that does nothing to make visitors happier — if anything, much of this stuff is deeply irritating and morally indefensible.


In isolation, the few seconds that it takes to load some extra piece of surveillance JavaScript isn’t much. Neither is the time it takes for a user to hide an email subscription box, or pause an autoplaying video. But these actions compound on a single webpage, and then again across multiple websites, and those seemingly-small time increments become a swirling miasma of frustration and pain.

Qualitatively, it makes using the Web feel so much slower on my iPhone that I try to avoid doing that.

A Spectre is Haunting Unicode

Paul McCann (via Karoy Lorentey):

However, after the JIS standard was released people noticed something strange - several of the added characters had no obvious sources, and nobody could tell what they meant or how they should be pronounced. Nobody was sure where they came from. These are what came to be known as the ghost characters (幽霊文字).


By interviewing the catalogers involved in the creation of the standard, the investigators established that some characters were inadvertently invented as mistakes in the cataloging process. For example, 妛 was an error introduced while trying to record “山 over 女”. “山 over 女” occurs in the name of a particular place and was thus suitable for inclusion in the JIS standard, but because they couldn’t print it as one character yet, 山 and 女 were printed separately, cut out, and pasted onto a sheet of paper, and then copied. When reading the copy, the line where the two little pieces of paper met looked like a stroke and was added to the character by mistake.

Previously: Unicode Waiting for New Japanese Era Name.

Rethinking the macOS Font Picker

Sam William Smith (via Matt Birchler):

The font picker is one of the most commonly used drop down menus in any creative application. Despite this, the default font picker on macOS has remained largely unchanged since the early days.

His example is from Keynote, one of the many apps that has implemented its own font picker because NSFontPanel can be kind of clunky. Cocoa should provide more built-in ways to pick fonts.