Contents at a Glance
Contents
About the Author
About the Technical
Reviewer
Acknowledgments
Introduction
Chapter 1: Hello Swift
Improvements over Objective-C
Type Inference
Type Safety
Control Flow
Optionals
Strings
Unicode
Other Improvements
Requirements
Getting Xcode
Quick Tour of Xcode
Quick Tour of Swift
Basic Types
Aggregate Types
Control Flow
Functions
Objects
Generics
Getting the Sample Code
Summary
Chapter 2: The Swift Playground in Xcode 6
Getting Started with a Playgorund
Custom QuickLook Plugins
XCShowView
XCCaptureValue
XCPSetExecutionShouldContinueIndefinitely
Custom Modules for Playground
Importing Your Code
Summary
Chapter 3: Accessing Swift’s Compiler and Interpreter: REPL
What is REPL?
LLDB and the Swift REPL
Summary
Chapter 4: Introduction to Object-Oriented Programming
The Concept Behind OOP
Indirection and Variables
Procedural Programming
Objected Oriented Implementation
Summary
Chapter 5: Constants, Variables, and Data Types
Type Annotation
Identifiers
Console Output
Integers
Floating-Point Numbers
Numeric Literals
Conversion
Booleans
Characters
Strings
Collection Types
Arrays
Dictionaries
Tuples
Optionals
Summary
Chapter 6: Operators
Syntax
Notation
Precedence
Associativity
Swift Operators
Prefix
Infix
Bitwise Shift (precedence 160)
Multiplicative (associativity left, precedence 150)
Additive (associativity, left precedence 140)
Range (precedence 135)
Cast (precedence 132)
Comparative (precedence 130)
Conjunctive (associativity, left precedence 120)
Disjunctive (associativity, left precedence 110)
Nil Coalescing (associativity, right precedence 110)
Ternary Conditional (associativity, right precedence 100)
Assignment (associativity, right precedence 90)
Postfix
Overloading Operators
Unary Operator
Binary Operators
Summary
Chapter 7: Flow Control
For Loops
For-in
For-conditional-Increment
While
Do-while
Branch Statements
Switch
Range Matching
Tuples
Value Binding
String Matching
Where Clause
Control Transfer Statements
Continue
Break
Fallthrough
Return
Labeled Statements
Summary
Chapter 8: Functions and Closures
Defining Functions
Calling a Function
Parameter Names
Default Values
Variadic Parameters
Mutablity of Parameters
In-Out Parameters
Function Types
Functions as Parameters
Functions as Return Values
Nested Functions
Closures
Closure Syntax
Inferring Types from Context
Implicit Returns
Shorthand Argument Names
Trailing Closures
Capturing Values
Summary
Chapter 9: Classes and Structures
Commonality
Definition
Accessing Properties
Value Types vs. Reference Types
Choosing Between Classes or Structures
Properties
Stored Properties
Lazy Stored Properties
Computed Properties
Property Observers
Type Properties
Summary
Chapter 10: Methods
Instance Methods
Modifying Type State
Type Methods
Summary
Chapter 11: Access Control
Modules and Source Files
Access Levels
Syntax
Classes
Subclassing
Class Members
Functions
Enumerations
Nested Types
Getters and Setters
Initializers
Protocols
Extensions
Typealias
Summary
Chapter 12: Inheritance
Terminology
Defining a Base Class
Subclassing
Properties
Preventing Overriding
Summary
Chapter 13: Extensions
Creating an Extension
Computed Properties
Initializers
Methods
Mutating Methods
Subscripts
Nested Types
Summary
Chapter 14: Memory Management and ARC
Object Life Cycle
Reference Counting
Object Ownership
ARC
Strong Reference Cycles
Resolving Strong Reference Cycles
Weak References
Unowned Reference
Strong Reference Cycles and Closures
Summary
Chapter 15: Protocols
Syntax
Properties
Methods
Initializers
Protocols as Types
Delegation
Conformance with Extensions
Protocols and Collection Types
Protocol Inheritance
Protocol Composition
Summary
Chapter 16: Generics
Generic Functions
Generic Types
Associated Types
Summary
Chapter 17: Expressions
Primary Expressions
Prefix Expressions
Postfix Expressions
Binary Expressions
Assignment Operator
Ternary Conditional
Casting Operators
Self and Super
Closures and Functions
Closures
Function Calls
Implicit Member Expression
Optionals
Summary
Chapter 18: Interoperability with Objective-C
Import Process
Interoperability
Object Initialization
Failable Initializers
Properties
Methods
Blocks
Object Comparison
Type Compatibility
Dynamic Dispatch
Selectors
Property Attributes
Namespaces and Class
Cocoa Data Types
Foundation Functions
Core Foundation
Interacting with C
Summary
Chapter 19: Mix and Match
Importing Objective-C into Swift in the Same App Target
Importing Swift into Objective-C in the Same App Target
Importing Objective-C into Swift in the Same Framework Target
Importing Swift into Objective-C in the Same Framework Target
Importing Frameworks
Using Swift in Objective-C
Summary
Chapter 20: Working with Core Data
NSManagedObjectContext
NSManagedObject
NSManagedObjectModel
NSPersistentStoreCoordinator
NSFetchRequest
NSPredicate
Creating An Application
Defining Data Objects
Adding an Object Editor
Showing the Editor
Entity Classes
Summary
Chapter 21: Consuming RESTful Services
HTTP Methods
Being Stateless
Endpoints
Data Formats
Network Access
Summary
Chapter 22: Developing a Swift-Based Application
The Project
Creating a Project
Creating A Sample
Detail View
Summary
Index