I’ve started a couple experiments in iOS 8 development using Apple’s new language Swift
and learned a few lessons that I want to share.

Blocks and Automatic Reference Counting (ARC)

Swift supports blocks, or “closures”, as other languages call them. You can provide a block as handler, e.g. for an asynchronous HTTP request. This is excellent if you want to do updates in the background and a simple way to handle some updates (data and UI) when the new data has arrived.

A block in Swift will capture references that are used form the surrounding context. If you use self reference in the block, a reference to it will be retained.

You can work around this by defining the captured references as weak references, specifically one of the following types:

unowned: the reference is handled like a regular reference in the closure but doesn’t count towards the strong references. This is the option to use when the block is actually contained and owned by the held reference (e.g. self).

weak: the reference is handled as Optional and could turn to nil at any point during execution.

UITableView Updates from Dynamic Data Sources

And another interesting thing, related to UIKit, not so much to Swift about updating UITableViews that show data from external services (e.g. via REST). This article on codeproject.com discusses a solution for Updating UITableView with dynamic data sources.