You are previewing Learn Swift 2 on the Mac, Second Edition.
O'Reilly logo
Learn Swift 2 on the Mac, Second Edition

Book Description

Swift is Apple's new, native, fast, and easy to learn programming language for iOS, watchOS, tvOS and OS X app development. It's their "Objective-C without the C". If you are an iOS developer or planning to become one, learning Swift is your #1 priority, and Learn Swift 2 on the Mac tells you everything you need to get up to speed, well, swiftly. The language is evolving very quickly, Apple has released version 2.1 of the langugae.

You'll start with the Swift Playground and an introduction to object-oriented programming so you can immediately see Swift in action. You then learn about all of the key language features like functions, closures, protocols, classes, methods, extensions, and how Swift works just as well as Objective-C when it comes to easy memory management with ARC.

Finally, you'll learn how to use Swift alongside Objective-C as well as with Core Data, and you'll learn how to put all of the pieces together with REST base application.

Table of Contents

  1. Cover
  2. Title
  3. Copyright
  4. Dedication
  5. Contents at a Glance
  6. Contents
  7. About the Author
  8. About the Technical Reviewer
  9. Acknowledgments
  10. Introduction
  11. Chapter 1: Hello Swift
    1. Improvements over Objective-C
      1. Type Inference
      2. Type Safety
      3. Control Flow
      4. Optionals
      5. Strings
      6. Unicode
      7. Other Improvements
    2. Requirements
    3. Getting Xcode
    4. Quick Tour of Xcode
    5. Quick Tour of Swift
      1. Basic Types
      2. Collection Types
      3. Control Flow
      4. Functions
      5. Objects
      6. Generics
      7. Getting the Sample Code
    6. Summary
  12. Chapter 2: The Swift Playground in Xcode
    1. Getting Started with a Playground
      1. Rich Text Comments
    2. Custom QuickLook Plug-Ins
      1. To develop custom plug-ins
      2. XCShowView
      3. XCCaptureValue
      4. XCPSetExecutionShouldContinueIndefinitely
    3. Custom Modules for Playground
      1. Importing Your Code
    4. Summary
  13. Chapter 3: Accessing Swift’s Compiler and Interpreter: REPL
    1. What Is REPL?
    2. LLDB and the Swift REPL
    3. Summary
  14. Chapter 4: Constants, Variables, and Data Types
    1. Type Annotation
    2. Identifiers
    3. Console Output
    4. Integers
    5. Floating-Point Numbers
    6. Numeric Literals
    7. Conversion
    8. Booleans
    9. Characters
    10. Strings
    11. Collection Types
      1. Arrays
      2. Sets
      3. Dictionaries
      4. Tuples
      5. Optionals
    12. Summary
  15. Expressions
    1. Primary Expressions
    2. Prefix Expressions
    3. Try Operator
      1. Postfix Expressions
    4. Binary Expressions
    5. Assignment Operator
    6. Ternary Conditional
    7. Casting Operators
    8. Self and Super expressionSuper
    9. Closures and Functions
    10. Closures
    11. Function Calls
    12. Implicit Member Expression
    13. Optionals
    14. Optional Chainning
    15. Summary
  16. Chapter 6: Operators
    1. Syntax
    2. Notation
    3. Precedence
    4. Associativity
    5. Swift Operators
      1. Prefix
      2. Infix
      3. Postfix
    6. Overloading Operators
      1. Unary Operator
      2. Binary Operators
    7. Summary
  17. Chapter 7: Flow Control
    1. For Loops
      1. For-in
      2. For-conditional-Increment
    2. While
    3. Repeat-while
    4. Branch Statements
    5. Switch
      1. Range Matching
    6. Control Transfer Statements
    7. Summary
  18. Chapter 8: Functions
    1. Defining Functions
    2. Calling a Function
    3. Parameter Names
    4. Default Values
    5. Variadic Parameters
    6. Mutablity of Parameters
    7. In-Out Parameters
    8. Function Types
    9. Functions as Parameters
    10. Functions as Return Values
    11. Nested Functions
    12. Summary
  19. Chapter 9: Closures
    1. Closure Syntax
    2. Inferring Types from Context
    3. Implicit Returns
    4. Shorthand Argument Names
    5. Trailing Closures
    6. Capturing Values
    7. Summary
  20. Chapter 10: Enumerations
    1. Syntax
    2. Switch Statement and Enumerations
    3. Associated Values
    4. Raw Values
    5. Recursive Enumerations
    6. Summary
  21. Chapter 11: Classes and Structures
    1. Commonality
    2. Definition
    3. Initialization
    4. Accessing Properties
    5. Value Types vs. Reference Types
    6. Choosing Between Classes or Structures
    7. Properties
    8. Stored Properties
    9. Lazy Stored Properties
    10. Computed Properties
    11. Property Observers
    12. Type Properties
    13. Summary
  22. Methods
    1. Instance Methods
    2. Modifying Type State
    3. Type Methods
    4. Summary
  23. Inheritance
    1. Terminology
    2. Defining a Base Class
    3. Subclassing
    4. Properties
    5. Preventing Overriding
    6. Summary
  24. Extensions
    1. Creating an Extension
    2. Computed Properties
    3. Initializers
    4. Methods
    5. Mutating Methods
    6. Subscripts
    7. Nested Types
    8. Summary
  25. Chapter 15: Memory Management and ARC
    1. Object Life Cycle
    2. Reference Counting
    3. Object Ownership
    4. ARC
    5. Strong Reference Cycles
    6. Resolving Strong Reference Cycles
    7. Weak References
    8. Unowned Reference
    9. Strong Reference Cycles and Closures
    10. Summary
  26. Chapter 16: Error Handling
    1. Representing Errors
    2. Handling Errors
    3. Propagating Errors
    4. Handling Errors
    5. Optional Handling
    6. Asserting Errors
    7. Cleanup Actions
    8. Summary
  27. Chapter 17: Protocols
    1. Syntax
      1. Properties
      2. Methods
    2. Initializers
      1. Protocols as Types
      2. Delegation
      3. Conformance with Extensions
      4. Protocols and Collection Types
      5. Protocol Inheritance
      6. Protocol Composition
    3. Protocol Conformance
    4. Optional Requirements
    5. Summary
  28. Chapter 18: Generics
    1. Generic Functions
    2. Generic Types
    3. Extensions
    4. Associated Types
    5. Summary
  29. Chapter 19: Access Control
    1. Modules and Source Files
    2. Access Levels
    3. Syntax
    4. Classes
    5. Subclassing
    6. Class Members
    7. Functions
    8. Enumerations
    9. Nested Types
    10. Getters and Setters
    11. Initializers
    12. Protocols
    13. Extensions
    14. Type Alias
    15. Summary
  30. Chapter 20: Interoperability with Objective-C
    1. Import Process
    2. Interoperability
    3. Nullability and Optionals
    4. Object Initialization
    5. Failable Initializers
    6. Properties
    7. Methods
    8. Blocks
    9. Object Comparison
    10. Type Compatibility
    11. Objective-C Generics
    12. Dynamic Dispatch
    13. Selectors
    14. Property Attributes
    15. Namespaces and Class
      1. Cocoa Data Types
    16. Foundation Functions
    17. Core Foundation
      1. Interacting with C
    18. Summary
  31. Chapter 21: Working with Core Data
    1. NSManagedObjectContext
    2. NSManagedObject
    3. NSManagedObjectModel
    4. NSPersistentStoreCoordinator
    5. NSFetchRequest
    6. NSPredicate
      1. Creating An Application
    7. Defining Data Objects
      1. Adding an Object Editor
    8. Showing the Editor
    9. Entity Classes
    10. Summary
  32. Chapter 22: Consuming RESTful Services
    1. HTTP Methods
    2. Being Stateless
    3. Endpoints
    4. Data Formats
    5. Network Access
    6. Security
    7. Summary
  33. Index