Contained in: Swift Apprentice: Beyond the Basics
patterns
iOS & Swift
Chapter in Swift Apprentice: Beyond the Basics
Pattern Matching
Apr 29 2025 · Chapter
With pattern matching, you can accomplish more with less typing, and it helps give Swift its modern language feel. This chapter picks up where “Swift Apprentice: Fundamentals - Chapter 4: Advanced Flow Control” left off and shows you powerful Swift idioms that let you work with switch statements, tuples, optionals…
iOS & Swift
Chapter in Swift Apprentice: Beyond the Basics
Value Types & Reference Types
Apr 29 2025 · Chapter
…distinct identities. Two identical twins could be alike in all physical attributes, but they are still distinct people. Two buffers could hold equal byte patterns, but they’re still distinct buffers. But the items on the value semantics list are all values. They lack identity, so talking about two things…
iOS & Swift
Chapter in Swift Apprentice: Beyond the Basics
Property Wrappers
Apr 29 2025 · Chapter
…with some abstractions from the last chapter. You’ll begin with a simple example and then see an implementation of the copy-on-write pattern. Finally, you’ll wrap up with another example showing you some things to watch out for when using this language feature. Basic Example Consider…
iOS & Swift
Chapter in Swift Apprentice: Beyond the Basics
Custom Operators, Subscripts & Keypaths
Apr 29 2025 · Chapter
…return the first argument raised to the power of the second one. Note the multiplication assignment operator in action. Note: You use the wildcard pattern to discard the loop’s values. You’ll learn more about it and other pattern matching techniques in “Chapter 4: Pattern Matching”. Now test your…
iOS & Swift
Chapter in Swift Apprentice: Beyond the Basics
Memory Management
Apr 29 2025 · Chapter
…self goes away, it gets set to nil. The code doesn’t crash anymore but generates a warning you can fix. The Weak-Strong Pattern The weak-strong pattern (sometimes affectionately called the weak-strong dance) also does not extend the lifetime of self but converts the weak reference…
iOS & Swift
Chapter in Swift Apprentice: Beyond the Basics
Concurrency
Apr 29 2025 · Chapter
…learn essential concepts, including: How to create unstructured and structured tasks. How to perform cooperative task cancellation. How to use the async / await pattern. How to create and use actor and Sendable types. Note: You may have heard of multithreaded programming. Concurrency in operating systems is built…
iOS & Swift
Chapter in Swift Apprentice: Beyond the Basics
Result Builders
Apr 29 2025 · Chapter
…return value of the result builder. Key Points Result builders have use beyond Apple’s SwiftUI. Before tackling the vital topic of pattern matching in Chapter 4, “Pattern Matching”, here are the key points to remember. Result builders let you define your own domain-specific language for declaring and configuring…
iOS & Swift
Chapter in Swift Apprentice: Beyond the Basics
Access Control, Code Organization & Testing
Apr 29 2025 · Chapter
…stuck. These came with the download or are available at the printed book’s source code link listed in the introduction. Challenge 1: Singleton Pattern A singleton is a design pattern that restricts the instantiation of a class to one object. Use access modifiers to create a singleton class Logger…