O'Reilly logo

Transitioning to Swift by Scott Gardner

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required