Chapter    6

Creating Functions

Swift functions are actually a type of closure, and Swift’s implementation of closures is both flexible and powerful—ranging from anonymous inline closures similar to Objective-C blocks, to complex functions extending far beyond the capabilities of an Objective-C method.

Swift functions are named closures that operate similarly to Objective-C methods. Closures can also be unnamed (aka, anonymous), in which case they are referred to as closure expressions. Closure expressions resemble Objective-C blocks that were introduced with iOS 4 and Mac OS X 10.6 in 2010—reportedly and coincidentally right around the time development of Swift began.

This chapter will compare Objective-C methods and blocks to Swift’s functions ...

Get Transitioning to Swift now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.