O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

iOS 12 Programming Fundamentals with Swift

Book Description

Move into iOS development by getting a firm grasp of its fundamentals, including the Xcode 10 IDE, Cocoa Touch, and the latest version of Apple’s acclaimed programming language, Swift 4.2. 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 lifecycle 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.

  • Self-synthesizing protocols
  • Conditional conformance
  • Dynamic member lookup
  • Multiple selection
  • Source control improvements
  • And more!

Once you master the fundamentals, you’ll be ready to tackle the details of iOS app development with author Matt Neuburg’s companion guide, Programming iOS 12.

Table of Contents

  1. Preface
    1. The Scope of This Book
    2. Versions
    3. Acknowledgments
    4. From the Programming iOS 4 Preface
    5. Conventions Used in This Book
    6. Using Code Examples
    7. Safari® Books Online
    8. How to Contact Us
  2. I. Language
    1. 1. The Architecture of Swift
      1. Ground of Being
      2. Everything Is an Object?
      3. Three Flavors of Object Type
      4. Variables
      5. Functions
      6. The Structure of a Swift File
      7. Scope and Lifetime
      8. Object Members
      9. Namespaces
      10. Modules
      11. Instances
      12. Why Instances?
      13. The Keyword self
      14. Privacy
      15. Design
        1. Object Types and APIs
        2. Instance Creation, Scope, and Lifetime
        3. Summary and Conclusion
    2. 2. Functions
      1. Function Parameters and Return Value
        1. Void Return Type and Parameters
        2. Function Signature
      2. External Parameter Names
      3. Overloading
      4. Default Parameter Values
      5. Variadic Parameters
      6. Ignored Parameters
      7. Modifiable Parameters
      8. Function in Function
      9. Recursion
      10. Function As Value
      11. Anonymous Functions
      12. Define-and-Call
      13. Closures
        1. How Closures Improve Code
        2. Function Returning Function
        3. Closure Setting a Captured Variable
        4. Closure Preserving Its Captured Environment
        5. Escaping Closures
      14. Curried Functions
      15. Function References and Selectors
        1. Function Reference Scope
        2. Selectors
    3. 3. Variables and Simple Types
      1. Variable Scope and Lifetime
      2. Variable Declaration
      3. Computed Initializer
      4. Computed Variables
      5. Setter Observers
      6. Lazy Initialization
      7. Built-In Simple Types
        1. Bool
        2. Numbers
        3. String
        4. Character and String Index
        5. Range
        6. Tuple
        7. Optional
    4. 4. Object Types
      1. Object Type Declarations and Features
        1. Initializers
        2. Properties
        3. Methods
        4. Subscripts
        5. Nested Object Types
        6. Instance References
      2. Enums
        1. Raw Values
        2. Associated Values
        3. Enum Case Iteration
        4. Enum Initializers
        5. Enum Properties
        6. Enum Methods
        7. Why Enums?
      3. Structs
        1. Struct Initializers, Properties, and Methods
        2. Struct As Namespace
      4. Classes
        1. Value Types and Reference Types
        2. Subclass and Superclass
        3. Class Initializers
        4. Class Deinitializer
        5. Class Properties and Methods
      5. Polymorphism
      6. Casting
        1. Casting Down
        2. Type Testing and Casting Down Safely
        3. Type Testing and Casting Optionals
        4. Bridging to Objective-C
      7. Type References
        1. From Instance to Type
        2. Type as Value
        3. The Keyword Self
        4. Comparing Types
        5. Summary of Type Terminology
      8. Protocols
        1. Why Protocols?
        2. Protocol Type Testing and Casting
        3. Declaring a Protocol
        4. Protocol Composition
        5. Optional Protocol Members
        6. Class Protocol
        7. Implicitly Required Initializers
        8. Literal Convertibles
      9. Generics
        1. Generic Declarations
        2. Contradictory Resolution
        3. Type Constraints
        4. Explicit Specialization
        5. Generic Invariance
        6. Associated Type Chains
        7. Where Clauses
      10. Extensions
        1. Extending Object Types
        2. Extending Protocols
        3. Extending Generics
      11. Umbrella Types
        1. Any
        2. AnyObject
        3. AnyClass
      12. Collection Types
        1. Array
        2. Dictionary
        3. Set
    5. 5. Flow Control and More
      1. Flow Control
        1. Branching
        2. Loops
        3. Jumping
      2. Privacy
        1. Private and Fileprivate
        2. Public and Open
        3. Privacy Rules
      3. Introspection
      4. Operators
      5. Synthesized Protocol Implementations
      6. Key Paths
      7. Dynamic Member Lookup
      8. Memory Management
        1. Memory Management of Reference Types
        2. Exclusive Access to Value Types
  3. II. IDE
    1. 6. Anatomy of an Xcode Project
      1. New Project
      2. The Project Window
        1. The Navigator Pane
        2. The Utilities Pane
        3. The Editor
      3. The Project File and Its Dependents
        1. What’s In the Project Folder
        2. Groups
      4. The Target
        1. Build Phases
        2. Build Settings
        3. Configurations
        4. Schemes and Destinations
      5. From Project to Built App
        1. Build Settings
        2. Property List Settings
        3. Nib Files
        4. Additional Resources
        5. Code Files
        6. Frameworks and SDKs
      6. The App Launch Process
        1. The Entry Point
        2. UIApplicationMain
        3. App Without a Storyboard
      7. Renaming Parts of a Project
    2. 7. Nib Management
      1. The Nib Editor Interface
        1. Document Outline
        2. Canvas
        3. Inspectors and Libraries
      2. Nib Loading
        1. When Nibs Are Loaded
        2. Manual Nib Loading
      3. Connections
        1. Outlets
        2. The Nib Owner
        3. Automatically Configured Nibs
        4. Misconfigured Outlets
        5. Deleting an Outlet
        6. More Ways to Create Outlets
        7. Outlet Collections
        8. Action Connections
        9. More Ways to Create Actions
        10. Misconfigured Actions
        11. Connections Between Nibs — Not!
      4. Additional Configuration of Nib-Based Instances
    3. 8. Documentation
      1. The Documentation Window
      2. Class Documentation Pages
      3. Quick Help
      4. Symbol Declarations
      5. Header Files
      6. Sample Code
      7. Internet Resources
    4. 9. Life Cycle of a Project
      1. Environmental Dependencies
        1. Permissible Runtime Environment
        2. Backward Compatibility
        3. Device Type
        4. Arguments and Environment Variables
        5. Conditional Compilation
      2. Version Control
      3. Editing and Navigating Your Code
        1. Autocompletion
        2. Snippets
        3. Fix-it and Live Syntax Checking
        4. Navigation
        5. Finding
        6. Refactoring
      4. Running in the Simulator
      5. Debugging
        1. Caveman Debugging
        2. The Xcode Debugger
      6. Testing
        1. Unit Tests
        2. Interface Tests
      7. Clean
      8. Running on a Device
        1. Obtaining a Developer Program Membership
        2. Signing an App
        3. Automatic Signing
        4. Manual Signing
        5. Running the App
        6. Managing Development Certificates and Devices
      9. Profiling
        1. Gauges
        2. Memory Debugging
        3. Instruments
      10. Localization
      11. Distribution
        1. Making an Archive
        2. The Distribution Certificate
        3. The Distribution Profile
        4. Distribution for Testing
        5. Final App Preparations
        6. Screenshots and Video Previews
        7. Property List Settings
        8. Submission to the App Store
  4. III. Cocoa
    1. 10. Cocoa Classes
      1. Subclassing
      2. Categories and Extensions
        1. How Swift Uses Extensions
        2. How You Use Extensions
        3. How Cocoa Uses Categories
      3. Protocols
        1. Informal Protocols
        2. Optional Methods
      4. Some Foundation Classes
        1. NSRange and NSNotFound
        2. NSString and Friends
        3. NSDate and Friends
        4. NSNumber
        5. NSValue
        6. NSData
        7. NSMeasurement and Friends
        8. Equality, Hashability, and Comparison
        9. NSArray and NSMutableArray
        10. NSDictionary and NSMutableDictionary
        11. NSSet and Friends
        12. NSIndexSet
        13. NSNull
        14. Immutable and Mutable
        15. Property Lists
        16. Codable
      5. Accessors, Properties, and Key–Value Coding
        1. Swift Accessors
        2. Key–Value Coding
        3. Uses of Key–Value Coding
        4. KVC and Outlets
        5. Cocoa Key Paths
      6. The Secret Life of NSObject
    2. 11. Cocoa Events
      1. Reasons for Events
      2. Subclassing
      3. Notifications
        1. Receiving a Notification
        2. Unregistering
        3. Posting a Notification
        4. Timer
      4. Delegation
        1. Cocoa Delegation
        2. Implementing Delegation
      5. Data Sources
      6. Actions
      7. The Responder Chain
        1. Deferring Responsibility
        2. Nil-Targeted Actions
      8. Key–Value Observing
        1. Registration and Notification
        2. Unregistering
        3. Key–Value Observing Example
      9. Swamped by Events
      10. Delayed Performance
    3. 12. Memory Management
      1. Principles of Cocoa Memory Management
      2. Rules of Cocoa Memory Management
      3. What ARC Is and What It Does
      4. How Cocoa Objects Manage Memory
      5. Autorelease Pool
      6. Memory Management of Instance Properties
      7. Retain Cycles and Weak References
      8. Unusual Memory Management Situations
        1. Notification Observers
        2. KVO Observers
        3. Timers
        4. Other Unusual Situations
      9. Nib Loading and Memory Management
      10. Memory Management of CFTypeRefs
      11. Property Memory Management Policies
      12. Debugging Memory Management Mistakes
    4. 13. Communication Between Objects
      1. Visibility by Instantiation
      2. Visibility by Relationship
      3. Global Visibility
      4. Notifications and Key–Value Observing
      5. Model–View–Controller
    5. A. C, Objective-C, and Swift
      1. The C Language
        1. C Data Types
        2. C Enums
        3. C Structs
        4. C Pointers
        5. C Arrays
        6. C Functions
      2. Objective-C
        1. Objective-C Objects and C Pointers
        2. Objective-C Objects and Swift Objects
        3. Exposure of Swift to Objective-C
        4. Bridged Types and Boxed Types
        5. Objective-C Methods
        6. Objective-C Initializers and Factories
        7. Selectors
        8. CFTypeRefs
        9. Blocks
        10. API Markup
      3. Bilingual Targets
  5. Index