Sunday, June 22, 2014

Interesting Swift Features

Mike Ash:

Because the collections use generic types, they have no problem containing structs. Object members work without difficulty. They basically become pass-by-value objects rather than a totally different entity.

The result is that small model classes become a lot nicer in Swift. How many times have you used an NSMutableDictionary with a few fixed keys to represent a bag of related data that really should have been a class? If you’re like me, the answer is “too many”. That’s because making a simple Objective-C class is a bit of a pain.


[The trailing closures feature] is interesting because it knocks down a visual barrier separating language constructs from library calls. As I discussed way back in 2008, blocks are a great addition to Objective-C because they allow you to write your own control constructs. This showed up in a huge way with GCD, which could provide a ton of useful asynchronous calls that worked a lot like language constructs, but were implemented as library calls. However, with Objective-C, there’s still a syntactic difference in how you write calls with blocks compared to how you use built-in language constructs.

Comments RSS · Twitter

Leave a Comment