Blog


Swift Closures Learn by Obj-C examples

Swift closures and Objective-C Blocks

Let’s talk about Swift Closures and how to use them. When blocks were introduced in Obj-C it made life pretty awesome for developing clean self contained method. In swift, they’re called closures but they work the same, remember a block is just a block of code, and a closure is just a closure (i.e. { }) of code.

Examples

In this first example we’re defining a method that will upload something as an asynchronous request. When the upload is finished,we want to execute a block — or closure 😉 — of code.