Code-free
Code-free

Swift: Manual retain/release

Old school

Russ Bishop
June 26, 2014

While creating ThreadLocalSlot<T>, I needed to call the posix posix_getspecific and posix_setspecific methods. Not only that, I needed to store an Objective-C object in a plain old void*. How can we accomplish that in Swift?

The key is Unmanaged. It contains magic sauce to let us turn an AnyObject into a COpaquePointer, which is . . .

Read More

Swift: Making Tuples Equatable

Lots of copypasta

Russ Bishop
June 23, 2014

Until we get a first-class macro system, this involves a lot of copypasta, but it does work:

@infix func == <T:Equatable> (lhs: (T), rhs: (T)) -> Bool { return lhs.0 == rhs.0 } @infix func == <T:Equatable, T2:Equatable> (lhs: (T,T2), rhs: (T,T2)) -> Bool { return lhs.0 == rhs.0 && lhs.1 == rhs.1 } @infix func == < . . .

Read More

Bigger iPhone and side-by-side iPad apps

Apple screams loudly, no one pays attention

Russ Bishop
June 23, 2014

Apple is telling us without telling us to get ready ASAP: Bigger iPhone screens and/or iPad side-by-side applications are coming and you should get ready.

The new size class mechanism and the resizable simulator are practically screaming at us to get with it.

My suggestion is to get comfortable with Auto Layout and make your views . . .

Read More

Swift: Storage for extension properties

Let's get in some trouble

Russ Bishop
June 23, 2014

A little birdy told me the Swift team has stored extension properties on their roadmap, but obviously we must await some future build or even revision of the language depending on when their schedule allows for it.

In the mean time, we can use objc_setAssociatedObject and objc_getAssociatedObject to simulate it. Unfortunately this only works . . .

Read More

Swift: Call by name

A blast from the past

Russ Bishop
June 23, 2014

Back when computers came with some assembly required and real men/women booted by toggling switches on the front panel, a language called Algol introduced many programmers to call-by-name parameter passing.

For many of today's languages, parameters to a function call are evaluated in the caller's context then copied to the callee. . . .

Read More

Swift Documentation Comments

Work in Progress

Russ Bishop
June 22, 2014

Update: A bug sometimes prevents Xcode from reading SwiftDocs for files other than the current file in a framework project, so you won't always see the doc comments in Quick Help or when Option-clicking a symbol. Hopefully the bug will be fixed.

Update #2: mattt of NSHipster fame heard from a little birdie that the doc comment format is . . .

Read More

#663399becca

Can't handle it

Russ Bishop
June 12, 2014

I can't write about Rebecca Meyers and what the Meyers family is going through for the same reasons as Jason Kottke:

Sometimes parents tend to get caught up in the minutia of parenthood: the logistics of getting from one place to another without losing your shit, the weary deflection of the 34th "why?" question of the . . .

Read More

Archive
  Subscribe by Email and Never Miss a Post