Retroactive modeling is the practice of using existing types to represent new concepts, without modifying those types. This technique is important for reusing existing structures, while maintaining compatibility with the current usage. Swift supports retroactive modeling through the use of extensions. Extensions enable you to add new functionality to existing types, without the need to have access to the original source code. Swift extensions are similar to categories in Objective-C, and can be used to extend a class, struct, enum,… [continue]
Swift Essentials: Closures
Most, if not all, programming languages have a construct for defining reusable sets of instructions. In Swift that construct is a closure. A closure is a self-contained chunk of code that is used to perform a specific task. The most basic type of closure is a named closure, which is more commonly known as a function. Functions (Named Closures) Every function is defined using the func keyword followed by the function name. The function name should describe the task that… [continue]
Swift Essentials: Optionals
Swift is designed to be safer than C-based programming languages. For example, Swift is a type safe language, that uses compile-time type checking to help catch errors early in the development process. And Swift uses type inference to enable the compiler to deduce types, requiring far fewer explicit type declarations. Another language feature that enhances safety is the optional. When you declare an instance in Swift, that instance must have a valid value for its type. If that instance can potentially be nil, then… [continue]