Learn Swift on the Mac: For OS X and iOS

Book description

There's a new language in town. Swift is Apple's new, native, fast, and easy to learn programming language for iOS 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 on the Mac tells you everything you need to get up to speed, well, swiftly.

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 and closures, 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 a health app using Apple's new HealthKit framework.

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. Aggregate 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 6
    1. Getting Started with a Playgorund
    2. Custom QuickLook Plugins
      1. XCShowView
      2. XCCaptureValue
      3. XCPSetExecutionShouldContinueIndefinitely
    3. Custom Modules for Playground
      1. Importing Your Code
      2. 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: Introduction to Object-Oriented Programming
    1. The Concept Behind OOP
    2. Indirection and Variables
    3. Procedural Programming
    4. Objected Oriented Implementation
      1. Summary
  15. Chapter 5: 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. Dictionaries
      3. Tuples
      4. Optionals
    12. 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. Do-while
    4. Branch Statements
    5. Switch
      1. Range Matching
      2. Control Transfer Statements
    6. Summary
  18. Chapter 8: Functions and Closures
    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. Closures
    13. Closure Syntax
    14. Inferring Types from Context
    15. Implicit Returns
    16. Shorthand Argument Names
    17. Trailing Closures
    18. Capturing Values
    19. Summary
  19. Chapter 9: Classes and Structures
    1. Commonality
    2. Definition
    3. Accessing Properties
    4. Value Types vs. Reference Types
    5. Choosing Between Classes or Structures
    6. Properties
    7. Stored Properties
    8. Lazy Stored Properties
    9. Computed Properties
    10. Property Observers
    11. Type Properties
    12. Summary
  20. Chapter 10: Methods
    1. Instance Methods
    2. Modifying Type State
    3. Type Methods
    4. Summary
  21. Chapter 11: 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. Typealias
    15. Summary
  22. Chapter 12: Inheritance
    1. Terminology
    2. Defining a Base Class
    3. Subclassing
    4. Properties
    5. Preventing Overriding
    6. Summary
  23. Chapter 13: Extensions
    1. Creating an Extension
    2. Computed Properties
    3. Initializers
    4. Methods
    5. Mutating Methods
    6. Subscripts
    7. Nested Types
    8. Summary
  24. Chapter 14: 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
  25. Chapter 15: 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. Summary
  26. Chapter 16: Generics
    1. Generic Functions
    2. Generic Types
    3. Associated Types
    4. Summary
  27. Chapter 17: Expressions
    1. Primary Expressions
    2. Prefix Expressions
      1. Postfix Expressions
    3. Binary Expressions
    4. Assignment Operator
    5. Ternary Conditional
    6. Casting Operators
    7. Self andSuper
    8. Closures and Functions
    9. Closures
    10. Function Calls
    11. Implicit Member Expression
    12. Optionals
    13. Summary
  28. Chapter 18: Interoperability with Objective-C
    1. Import Process
    2. Interoperability
    3. Object Initialization
    4. Failable Initializers
    5. Properties
    6. Methods
    7. Blocks
    8. Object Comparison
    9. Type Compatibility
    10. Dynamic Dispatch
    11. Selectors
    12. Property Attributes
    13. Namespaces and Class
      1. Cocoa Data Types
    14. Foundation Functions
    15. Core Foundation
      1. Interacting with C
    16. Summary
  29. Chapter 19: Mix and Match
    1. Importing Objective-C into Swift in the Same App Target
    2. Importing Swift into Objective-C in the Same App Target
    3. Importing Objective-C into Swift in the Same Framework Target
    4. Importing Swift into Objective-C in the Same Framework Target
    5. Importing Frameworks
    6. Using Swift in Objective-C
    7. Summary
  30. Chapter 20: 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
  31. Chapter 21: Consuming RESTful Services
    1. HTTP Methods
    2. Being Stateless
    3. Endpoints
    4. Data Formats
    5. Network Access
    6. Summary
  32. Chapter 22: Developing a Swift-Based Application
    1. The Project
      1. Creating a Project
      2. Creating A Sample
      3. Detail View
    2. Summary
  33. Index

Product information

  • Title: Learn Swift on the Mac: For OS X and iOS
  • Author(s):
  • Release date: March 2015
  • Publisher(s): Apress
  • ISBN: 9781484203767