0%

Move into iOS development by getting a firm grasp of its fundamentals, including the Xcode 13 IDE, Cocoa Touch, and the latest version of Apple's acclaimed programming language, Swift 5.5. With this thoroughly updated guide, you'll learn the Swift language, understand Apple's Xcode development tools, and discover the Cocoa framework.

  • Explore Swift's object-oriented concepts
  • Become familiar with built-in Swift types
  • Dive deep into Swift objects, protocols, and generics
  • Tour the life cycle of an Xcode project
  • Learn how nibs are loaded
  • Understand Cocoa's event-driven design
  • Communicate with C and Objective-C

In this edition, catch up on the latest iOS programming features:

  • Structured concurrency: async/await, tasks, and actors
  • Swift native formatters and attributed strings
  • Lazy locals and throwing getters
  • Enhanced collections with the Swift Algorithms and Collections packages
  • Xcode tweaks: column breakpoints, package collections, and Info.plist build settings
  • Improvements in Git integration, localization, unit testing, documentation, and distribution
  • And more!

Table of Contents

  1. Preface
    1. The Scope of This Book
    2. From the Preface to the First Edition (Programming iOS 4)
    3. Versions
    4. Acknowledgments
    5. Conventions Used in This Book
    6. Using Code Examples
    7. O’Reilly Online Learning
    8. How to Contact Us
  2. I. Language
    1. 1. The Architecture of Swift
    2. Ground of Being
    3. Everything Is an Object?
    4. Three Flavors of Object Type
    5. Variables
    6. Functions
    7. The Structure of a Swift File
    8. Scope and Lifetime
    9. Object Members
    10. Namespaces
    11. Modules
    12. Instances
    13. Why Instances?
    14. The Keyword self
    15. Privacy
    16. Design
    17. 2. Functions
    18. Function Parameters and Return Value
    19. Void Return Type and Parameters
    20. Function Signature
    21. External Parameter Names
    22. Overloading
    23. Default Parameter Values
    24. Variadic Parameters
    25. Ignored Parameters
    26. Modifiable Parameters
    27. Calling Objective-C with Modifiable Parameters
    28. Called by Objective-C with Modifiable Parameters
    29. Reference Type Modifiable Parameters
    30. Function in Function
    31. Recursion
    32. Function as Value
    33. Anonymous Functions
    34. Using Anonymous Functions Inline
    35. Anonymous Function Abbreviated Syntax
    36. Define-and-Call
    37. Closures
    38. How Closures Improve Code
    39. Function Returning Function
    40. Closure Setting a Captured Variable
    41. Closure Preserving Captured Environment
    42. Escaping Closures
    43. Capture Lists
    44. Curried Functions
    45. Function References and Selectors
    46. Function Reference Scope
    47. Selectors
    48. 3. Variables and Simple Types
    49. Variable Scope and Lifetime
    50. Variable Declaration
    51. Computed Variable Initialization
    52. Computed Variables
    53. Computed Properties
    54. Property Wrappers
    55. Setter Observers
    56. Lazy Initialization
    57. Singleton
    58. Lazy Initialization of Instance Properties
    59. Built-In Simple Types
    60. Bool
    61. Numbers
    62. String
    63. Character and String Index
    64. Range
    65. Tuple
    66. Optional
    67. 4. Object Types
    68. Object Type Declarations and Features
    69. Initializers
    70. Properties
    71. Methods
    72. Subscripts
    73. Nested Object Types
    74. Enums
    75. Raw Values
    76. Associated Values
    77. Enum Case Iteration
    78. Enum Initializers
    79. Enum Properties
    80. Enum Methods
    81. Why Enums?
    82. Structs
    83. Struct Initializers
    84. Struct Properties
    85. Struct Methods
    86. Classes
    87. Value Types and Reference Types
    88. Subclass and Superclass
    89. Class Initializers
    90. Class Deinitializer
    91. Class Properties
    92. Static/Class Members
    93. Polymorphism
    94. Casting
    95. Casting Down
    96. Type Testing and Casting Down Safely
    97. Type Testing and Casting Optionals
    98. Bridging to Objective-C
    99. Type References
    100. From Instance to Type
    101. From self to Type
    102. Type as Value
    103. Summary of Type Terminology
    104. Comparing Types
    105. Protocols
    106. Why Protocols?
    107. Adopting a Library Protocol
    108. Protocol Type Testing and Casting
    109. Declaring a Protocol
    110. Protocol Composition
    111. Class Protocols
    112. Optional Protocol Members
    113. Implicitly Required Initializers
    114. Expressible by Literal
    115. Generics
    116. Generic Declarations
    117. Type Constraints
    118. Explicit Specialization
    119. Generic Types and Covariance
    120. Associated Type Chains
    121. Where Clauses
    122. Extensions
    123. Extending Protocols
    124. Extending Generics
    125. Umbrella Types
    126. Any
    127. AnyObject
    128. AnyClass
    129. Collection Types
    130. Array
    131. Dictionary
    132. Set
    133. OrderedSet and OrderedDictionary
    134. 5. Flow Control and More
    135. Flow Control
    136. Branching
    137. Loops
    138. Jumping
    139. Privacy
    140. Private and Fileprivate
    141. Public and Open
    142. Privacy Rules
    143. Introspection
    144. Operators
    145. Memory Management
    146. Memory Management of Reference Types
    147. Exclusive Access to Value Types
    148. Miscellaneous Swift Language Features
    149. Synthesized Protocol Implementations
    150. Key Paths
    151. Instance as Function
    152. Dynamic Membership
    153. Property Wrappers
    154. Custom String Interpolation
    155. Reverse Generics
    156. Result Builders
    157. Result
    158. 6. Structured Concurrency
    159. Multithreading
    160. The Main Thread
    161. Background Threads
    162. Asynchronous Code
    163. Structured Concurrency Syntax
    164. async/await
    165. Async Contexts
    166. Tasks
    167. Wrapping a Completion Handler
    168. Multiple Concurrent Tasks
    169. async let
    170. Task Groups
    171. Asynchronous Sequences
    172. Built-in Asynchronous Sequences
    173. Making an Asynchronous Sequence
    174. Asynchronous Sequence Methods
    175. Actors
    176. Actor Isolation
    177. Actor Serialization
    178. The Main Actor
    179. Context Switching
    180. Implicit Context Switching
    181. Explicit Context Switching
    182. More About Tasks
    183. Task Priority
    184. The Current Task
    185. Sleeping
    186. Yielding
    187. Cancellation
    188. More About Actors
    189. Reentrancy
    190. The Keyword nonisolated
    191. The Keyword isolated
    192. Global Actors
    193. Sendable
  3. II. IDE
    1. 7. Anatomy of an Xcode Project
    2. New Project
    3. The Project Window
    4. The Navigator Pane
    5. The Inspector Pane
    6. The Editor
    7. Project File and Dependents
    8. Contents of the Project Folder
    9. Groups
    10. The Target
    11. Build Phases
    12. Build Settings
    13. Configurations
    14. Schemes and Destinations
    15. From Project to Built App
    16. Build Settings
    17. Property List Settings
    18. Nib Files
    19. Resources
    20. Code Files
    21. Frameworks and SDKs
    22. Swift Packages
    23. The App Launch Process
    24. The Entry Point
    25. How an App Gets Going
    26. App Without a Storyboard
    27. Renaming Parts of a Project
    28. 8. Nib Files
    29. The Nib Editor Interface
    30. Document Outline
    31. Canvas
    32. Inspectors
    33. Loading a Nib
    34. Loading a View Controller Nib
    35. Loading a Main View Nib
    36. Loading a View Nib Manually
    37. Connections
    38. Outlets
    39. The Nib Owner
    40. Automatically Configured Nibs
    41. Misconfigured Outlets
    42. Deleting an Outlet
    43. More Ways to Create Outlets
    44. Outlet Collections
    45. Action Connections
    46. More Ways to Create Actions
    47. Misconfigured Actions
    48. Connections Between Nibs — Not!
    49. Additional Configuration of Nib-Based Instances
    50. 9. Documentation
    51. The Documentation Window
    52. Class Documentation Pages
    53. Quick Help
    54. Documenting Frameworks and Packages
    55. Symbol Declarations
    56. Header Files
    57. Sample Code
    58. Internet Resources
    59. 10. Life Cycle of a Project
    60. Environmental Dependencies
    61. Conditional Compilation
    62. Build Action
    63. Permissible Runtime Environment
    64. Backward Compatibility
    65. Device Type
    66. Arguments and Environment Variables
    67. Version Control
    68. Editing and Navigating Your Code
    69. Text Editing Preferences
    70. Multiple Selection
    71. Code Completion and Placeholders
    72. Snippets
    73. Refactoring and Code Actions
    74. Fix-it and Live Syntax Checking
    75. Navigation
    76. Finding
    77. Running in the Simulator
    78. Debugging
    79. Caveman Debugging
    80. The Xcode Debugger
    81. Testing
    82. Unit Tests
    83. Interface Tests
    84. Test Plans
    85. Massaging the Report
    86. Clean
    87. Running on a Device
    88. Obtaining a Developer Program Membership
    89. Signing an App
    90. Automatic Signing
    91. Manual Signing
    92. Running the App
    93. Managing Development Certificates and Devices
    94. Profiling
    95. Gauges
    96. Memory Debugging
    97. Instruments
    98. Localization
    99. Creating Localized Content
    100. Testing Localization
    101. Distribution
    102. Making an Archive
    103. The Distribution Certificate
    104. The Distribution Profile
    105. Distribution for Testing
    106. Final App Preparations
    107. Screenshots and Video Previews
    108. Property List Settings
    109. Submission to the App Store
  4. III. Cocoa
    1. 11. Cocoa Classes
    2. Subclassing
    3. Categories and Extensions
    4. How Swift Uses Extensions
    5. How You Use Extensions
    6. How Cocoa Uses Categories
    7. Protocols
    8. Optional Members
    9. Informal Protocols
    10. Some Foundation Classes
    11. NSRange
    12. NSNotFound
    13. NSString and Friends
    14. NSDate and Friends
    15. NSNumber
    16. NSValue
    17. NSData
    18. NSMeasurement and Friends
    19. Equality, Hashability, and Comparison
    20. NSArray and NSMutableArray
    21. NSDictionary and NSMutableDictionary
    22. NSSet and Friends
    23. NSIndexSet
    24. NSNull
    25. Immutable and Mutable
    26. Property Lists
    27. Codable
    28. Accessors, Properties, and Key–Value Coding
    29. Swift Accessors
    30. Key–Value Coding
    31. How Outlets Work
    32. Cocoa Key Paths
    33. Uses of Key–Value Coding
    34. KeyPath Notation
    35. The Secret Life of NSObject
    36. 12. Cocoa Events
    37. Reasons for Events
    38. Subclassing
    39. Notifications
    40. Receiving a Notification
    41. Unregistering
    42. Subscribing to a Notification
    43. Posting a Notification
    44. Timer
    45. Delegation
    46. Cocoa Delegation
    47. Implementing Delegation
    48. Data Sources
    49. Actions
    50. The Responder Chain
    51. Nil-Targeted Actions
    52. Key–Value Observing
    53. Registration and Notification
    54. Unregistering
    55. Key–Value Observing Example
    56. Swamped by Events
    57. Delayed Performance
    58. 13. Memory Management
    59. Principles of Cocoa Memory Management
    60. Rules of Cocoa Memory Management
    61. What ARC Is and What It Does
    62. How Cocoa Objects Manage Memory
    63. Autorelease Pool
    64. Memory Management of Instance Properties
    65. Retain Cycles and Weak References
    66. Unusual Memory Management Situations
    67. Notification Observers
    68. KVO Observers
    69. Timers
    70. Other Unusual Situations
    71. Memory Management of CFTypeRefs
    72. Property Memory Management Policies
    73. Debugging Memory Management Mistakes
    74. 14. Communication Between Objects
    75. Visibility Through an Instance Property
    76. Visibility by Instantiation
    77. Getting a Reference
    78. Visibility by Relationship
    79. Global Visibility
    80. Notifications and Key–Value Observing
    81. The Combine Framework
    82. Alternative Architectures
    83. Model–View–Controller
    84. Router and Data Space
    85. Model–View–Presenter
    86. Protocols and Reactive Programming
    87. SwiftUI
    88. Result Builders and Modifiers
    89. State Properties
    90. Bindings
    91. Passing Data Downhill
    92. Passing Data Uphill
    93. Custom State Objects
    94. A. C, Objective-C, and Swift
    95. The C Language
    96. C Data Types
    97. C Enums
    98. C Structs
    99. C Pointers
    100. C Arrays
    101. C Strings
    102. C Functions
    103. Objective-C
    104. Objective-C Objects and C Pointers
    105. Objective-C Objects and Swift Objects
    106. Exposure of Swift to Objective-C
    107. Bridged Types and Boxed Types
    108. Objective-C Methods
    109. Selectors
    110. CFTypeRefs
    111. Blocks
    112. API Markup
    113. Bilingual Targets
  5. Index
54.175.70.29