
iOS 11 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics

Encapsulating function-calling in a function can reduce repetition and opportunity for error. Moreover, the other function may call the parameter function in some special way; for example, it might call it after doing other things, or at some later time.
Matt Neuburg • iOS 11 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics
Eventually, you may want to do some further reading on effective planning and construction of the architecture of an object-based program. I recommend in particular two classic, favorite books. Refactoring, by Martin Fowler (Addison-Wesley, 1999), describes why you might need to rearrange what methods belong to what classes (and how to conquer your
... See moreMatt Neuburg • iOS 11 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics
Anonymous Functions
Matt Neuburg • iOS 11 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics
Unfortunately, there’s a hole in the Swift language: there’s no way to convert an array into a comma-separated list of arguments (comparable to splatting in Ruby). If what you’re starting with is an array of some type, you can’t use it where a variadic of that type is expected.
Matt Neuburg • iOS 11 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics
The top-level namespaces are modules. By default, your app is a module and hence a namespace; that namespace’s name is, roughly speaking, the name of the app.
Matt Neuburg • iOS 11 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics
We may summarize the nature of objects in two phrases: encapsulation of functionality, and maintenance of state.
Matt Neuburg • iOS 11 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics
In Swift, every noun is an object, and every verb is a message.
Matt Neuburg • iOS 11 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics
To sum up: A class declaration defines a namespace. This namespace requires that other objects use an extra level of dot-notation to refer to what’s inside the namespace, but other objects can still refer to what’s inside the namespace; the namespace does not, in and of itself, close any doors of visibility. The private keyword lets you close those
... See moreMatt Neuburg • iOS 11 Programming Fundamentals with Swift: Swift, Xcode, and Cocoa Basics
So Swift has three kinds of object type: classes, structs, and enums. I like to refer to these as the three flavors of object type.