You are previewing Swift in 24 Hours, Sams Teach Yourself.
O'Reilly logo
Swift in 24 Hours, Sams Teach Yourself

Book Description

In just 24 lessons of one hour or less, Sams Teach Yourself Swift in 24 Hours helps you build next-generation OS X and iOS apps with Apple’s new Swift programming language.

This book’s straightforward, step-by-step approach helps you quickly master Swift’s core concepts, structure, and syntax and use Swift to write safe, powerful, modern code. In just a few hours you’ll be applying advanced features such as extensions, closures, protocols, and generics. Every lesson builds on what you’ve already learned, giving you a rock-solid foundation for real-world success.

Step-by-step instructions carefully walk you through the most common Swift development tasks.
Practical, hands-on examples show you how to apply what you learn.
Quizzes and exercises help you test your knowledge and stretch your skills.
Notes and tips point out shortcuts and solutions.

Learn how to...

  • Set up your Swift development environment

  • Master Swift’s fundamental data types and operators

  • Make the most of arrays and dictionaries

  • Control program flow, modify execution paths, and iterate code

  • Perform complex actions with functions

  • Work with higher-order functions and closures

  • Harness the power of structs, enums, classes, and class inheritance

  • Customize initializers of classes, structs, and enums

  • Implement instance methods, type methods, and advanced type functionality

  • Take full advantage of Swift’s advanced memory allocation

  • Extend type functionality with protocols and extensions

  • Leverage the power of generics, chaining, and other advanced features

  • Interoperate with Objective-C code

  • Interact with user interfaces

  • Take advantage of Swift’s Standard Library features and functions

  • Who Should Read this Book

  • Beginner-intermediate level programmers

  • Advanced programmers who are not yet familiar with Swift can benefit

  • Table of Contents

    1. About This eBook
    2. Title Page
    3. Copyright Page
    4. Contents at a Glance
    5. Table of Contents
    6. About the Author
    7. Dedication
    8. Acknowledgments
    9. We Want to Hear from You!
    10. Reader Services
    11. Introduction
      1. Who Should Read This Book?
      2. What Should You Expect from This Book?
    12. Hour 1. Introducing the Swift Development Environment
      1. What Is Swift?
      2. Getting Started
      3. Summary
      4. Q&A
      5. Workshop
      6. Exercise
    13. Hour 2. Learning Swift’s Fundamental Data Types
      1. Constants in Swift
      2. Variables in Swift
      3. Introducing Data Types
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercise
    14. Hour 3. Using Operators in Swift
      1. Unary Operators
      2. Binary Operators
      3. Ternary Conditional Operators
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercise
    15. Hour 4. Working with Collection Types
      1. Arrays
      2. Dictionaries
      3. Tuples
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercise
    16. Hour 5. Understanding Optional Values
      1. What Are Optional Values?
      2. How to Designate a Variable as Optional
      3. Wrapping and Unwrapping Optional Variables
      4. Use Case for Optionals
      5. Summary
      6. Q&A
      7. Workshop
      8. Exercise
    17. Hour 6. Controlling Program Flow with Conditionals
      1. The if Statement
      2. The switch Statement
      3. Summary
      4. Q&A
      5. Workshop
      6. Exercise
    18. Hour 7. Iterating Code with Loops
      1. Two Categories of Loops
      2. Transferring Control in Loops
      3. Summary
      4. Q&A
      5. Workshop
      6. Exercise
    19. Hour 8. Using Functions to Perform Actions
      1. The Nature of Functions in Swift
      2. General Function Syntax and Structure
      3. Functions with No Parameters and No Return Type
      4. The Type of a Function
      5. Functions with Parameters
      6. Functions with Variadic Parameters
      7. Functions with Return Types
      8. External Parameter Names
      9. Default Parameter Values
      10. Change Argument Values with In-Out Parameters
      11. Summary
      12. Q&A
      13. Workshop
      14. Exercise
    20. Hour 9. Understanding Higher Order Functions and Closures
      1. Higher Order Functions
      2. Closures
      3. Summary
      4. Q&A
      5. Workshop
      6. Exercise
    21. Hour 10. Learning About Structs and Classes
      1. Overview of Structs and Classes in Swift
      2. What Swift Structs and Classes Have in Common
      3. Differences Between Structs and Classes
      4. When to Use a Class or a Struct
      5. Summary
      6. Q&A
      7. Workshop
      8. Exercise
    22. Hour 11. Implementing Class Inheritance
      1. What Is Inheritance?
      2. Identifying a Base Class
      3. Creating a Subclass
      4. Overriding Inherited Methods
      5. Accessing super
      6. Preventing Overrides
      7. Class Identity
      8. Summary
      9. Q&A
      10. Workshop
      11. Exercise
    23. Hour 12. Harnessing the Power of Enums
      1. Understanding Swift Enums
      2. Swift Enum Structure
      3. Raw Values
      4. Enum Shorthand Syntax
      5. Associated Values
      6. Switching Enum Values
      7. Adding Instance Methods to Enums
      8. Summary
      9. Q&A
      10. Workshop
      11. Exercise
    24. Hour 13. Customizing Initializers of Classes, Structs, and Enums
      1. Initialization
      2. Initializing Value Types
      3. Advanced Initialization
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercise
    25. Hour 14. Digging Deeper with Properties
      1. Stored Properties
      2. Computed Properties
      3. Property Accessors
      4. Property Observers
      5. Inheriting and Overriding Accessors
      6. Inheriting and Overriding Observers
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercise
    26. Hour 15. Adding Advanced Type Functionality
      1. Type Properties and Methods
      2. Type Aliasing
      3. Type Access Control
      4. Subscripts
      5. Type Casting and Non-Specific Types
      6. Summary
      7. Q&A
      8. Workshop
      9. Exercise
    27. Hour 16. Understanding Memory Allocation and References
      1. Deinitialization
      2. Automatic Reference Counting
      3. Summary
      4. Q&A
      5. Workshop
      6. Exercise
    28. Hour 17. Using Protocols to Define Behavior
      1. Defining Protocols
      2. Creating and Adopting Protocols
      3. Properties
      4. Defining Methods in Protocols
      5. Using Protocol Names as Types
      6. Adopting and Inheriting Multiple Protocols
      7. Optional Protocol Properties and Methods
      8. How to Check for Protocol Conformance
      9. Using Protocols for Delegation
      10. Summary
      11. Q&A
      12. Workshop
      13. Exercise
    29. Hour 18. Using Extensions to Add Type Functionality
      1. Defining Extensions
      2. Adding Functionality with Extensions
      3. Summary
      4. Q&A
      5. Workshop
      6. Exercise
    30. Hour 19. Working with Optional Chaining
      1. Defining Optional Chaining
      2. Chaining Optional Properties
      3. Subscripts
      4. Methods
      5. Summary
      6. Q&A
      7. Workshop
      8. Exercise
    31. Hour 20. Introducing Generics
      1. An Introduction to Generics
      2. Type Parameters and Placeholder Types
      3. Specifying Type Constraints
      4. Creating Generic Types
      5. Extending Generic Types
      6. Using Associated Types in Protocols
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercise
    32. Hour 21. Adding Interoperability with Objective-C
      1. Objective-C Basics
      2. Bridging
      3. Integrating Swift into an Objective-C App
      4. Summary
      5. Q&A
      6. Workshop
      7. Exercise
    33. Hour 22. Interacting with User Interfaces
      1. Interface Introduction
      2. Interface Definitions
      3. Building an Interface
      4. Creating Your Own Project
      5. Adding UI Elements
      6. Summary
      7. Q&A
      8. Workshop
      9. Exercise
    34. Hour 23. Asynchronous Programming in Swift
      1. The Problem That Concurrency Solves
      2. Different Types of Queues
      3. Asynchronous Programming in Action
      4. Add iTunes Search to Songs App
      5. Parsing JSON
      6. Summary
      7. Q&A
      8. Workshop
      9. Exercise
    35. Hour 24. Learning Swift’s Standard Library Functions
      1. What Is a Standard Library?
      2. Numeric Types
      3. String Type
      4. Protocols
      5. Functional Functions
      6. Global Functions
      7. Summary
      8. Q&A
      9. Workshop
      10. Exercise
    36. Index
    37. Code Snippets