Chapter 9

Functioning Successfully

In This Chapter

arrow Looking at functions

arrow Adding functions for location support

arrow Creating an action function

In Swift, functions and types play a larger role than they do in some other object-oriented languages. The whole idea of objects containing both data and functionality (or, in Swift terms, properties and methods) is central.

It makes for a neat package.

Named types share important characteristics with objects. One of the most important shared characteristics is that all named types can contain functions: Yes, you can place functions in structures and enumerations as well as in classes. (In classes, however, functions are generally referred to as methods.)

icon tip That last point is very important. This chapter is about functions wherever they reside — in classes, enumerations, structures, or even inside other functions or at a global level of your app. When in classes, functions are referred to as methods, but they’re still functions underneath. Keep this in mind as you read this chapter.

In ’ Chapter 4, you set up Locatapp to use as a running example ...

Get Swift For Dummies 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.