Swift For Dummies

Book description

Get up and running with Swift—swiftly

Brimming with expert advice and easy-to-follow instructions, Swift For Dummies shows new and existing programmers how to quickly port existing Objective-C applications into Swift and get into the swing of the new language like a pro. Designed from the ground up to be a simpler programming language, it's never been easier to get started creating apps for the iPhone or iPad, or applications for Mac OS X.

Inside the book, you'll find out how to set up Xcode for a new Swift application, use operators, objects, and data types, and control program flow with conditional statements. You'll also get the scoop on creating new functions, statements, and declarations, learn useful patterns in an object-oriented environment, and take advantage of frameworks to speed your coding along. Plus, you'll find out how Swift does away with pointer variables and how to reference and dereference variables instead.

  • Set up a playground development environment for Mac, iPhone, iPad, and wearable computers
  • Move an existing Objective-C program to Swift
  • Take advantage of framework components and subcomponents
  • Create an app that uses location, mapping, and social media

Whether you're an existing Objective-C programmer looking to port your code to Swift or you've never programmed for Apple in the past, this fun and friendly guide gets you up to speed swiftly.

Table of contents

    1. Cover
    2. Title Page
    3. Introduction
      1. About This Book
      2. Foolish Assumptions
      3. Icons Used in This Book
      4. Beyond the Book
      5. Where to Go from Here
    4. Part I: Getting Started with Swift
      1. Chapter 1: Setting Up an Xcode Swift Project
        1. Looking Ahead to the End
        2. Working with Swift
        3. Getting the Developer Tools
        4. Setting Up Your Mac
        5. Planning Your Environment
        6. Getting Started with Swift
        7. Exploring Your Project
      2. Chapter 2: Playing in the Playground
        1. Creating a Playground
        2. Using a Playground
        3. Using the Timeline in the Playground
      3. Chapter 3: Using the Xcode Editing Tools
        1. Getting Started with Editing Tools
        2. Completing Code with Code Completion
        3. Using Fix-It to Correct Code
        4. Folding and Unfolding Code
        5. Using Code Snippets
      4. Chapter 4: Creating a Swift App
        1. Double-Checking Your Environment
        2. Creating the Project
        3. Testing the Template
        4. Setting the Location for iOS Simulator
        5. Adding the Map to the Storyboard and Project
        6. Testing the App
        7. Adding Swift Code to Locatapp
        8. Testing the App with Location Data
    5. Part II: Introducing Actions
      1. Chapter 5: Operating on Data
        1. Classifying Operators
        2. Answering Syntax Questions with Playgrounds
        3. Clearing the Way for Operators
        4. Assigning Values with Assignment Operators
        5. Counting On Arithmetic Operators for Math
        6. Addition
        7. Multiplication
        8. Division
        9. Incrementing and decrementing numeric values
        10. Combining operators
        11. Comparing values
        12. Choosing and Checking Values with Logical Operators
      2. Chapter 6: Using Swift Types
        1. Understanding Types and Type Safety
        2. Swift Standard Library Types
        3. Specifying Variable or Expression Types with Type Annotations
        4. Dealing with Tuples
        5. Working with Optional Types
        6. Using Generic Types
      3. Chapter 7: Collecting Objects
        1. Playing by Swift Collection Rules
        2. Organizing Data Sequentially with Arrays
        3. Organizing Data Logically with Dictionaries
      4. Chapter 8: Controlling the Flow
        1. Looping through Code
        2. Using Conditions
        3. Transferring Control
        4. Using Assertions
      5. Chapter 9: Functioning Successfully
        1. Setting the Stage for the Social Media Location App
        2. Exploring the Functions in Locatapp
        3. Understanding the Locatapp Architecture
        4. Uncovering the Function Features
        5. Adding Location Support
    6. Part III: Putting Expressions Together
      1. Chapter 10: Expressing Yourself
        1. Surveying the Types of Swift Expressions
        2. Understanding Lazy Loading
      2. Chapter 11: Declaring the Symbols
        1. Navigating through Symbols with the Symbol Navigator
        2. Preventing Disasters with Assertions
        3. Patterns
        4. Ranges
      3. Chapter 12: Initializing and Deinitializing Data
        1. Understanding Initialization
        2. Performing Initialization
        3. Understanding Deinitialization
    7. Part IV: Using Components and Subcomponents
      1. Chapter 13: Expanding Objects with Extensions
        1. Working with a Swift Extension
        2. Using Swift Extensions with a Built-In Class
      2. Chapter 14: Managing Access Control for Your Objects
        1. Introducing Access Control Levels
        2. Using Swift Access Control Terminology
      3. Chapter 15: Building Classes, Structures, and Enumerations
        1. Exploring Classes, Structures, and Enumerations
        2. Declaring a Simple Class
        3. Exploring a Swift Class, Structure, or Enumeration File
      4. Chapter 16: Using Properties, Variables, Outlets, and Actions
        1. Understanding Properties and Variables
        2. Encapsulating Data for Good Design and Maintainability
        3. Understanding Properties and Variables in Locatapp
        4. Declaring Outlets and Actions
      5. Chapter 17: Working with Enumerations to Consolidate Values
        1. Using Enumerations with Swift
        2. Understanding Traditional C Structures and Enumerations
        3. Exploring Swift Enumerations
      6. Chapter 18: Using Protocols to Provide Templates for Functionality
        1. Understanding Protocols
        2. Experimenting with Protocols
        3. Exploring Protocols and a UITableViewController
      7. Chapter 19: Mixing Objective-C and Swift
        1. Comparing Frameworks in Objective-C and Swift
        2. Calling an Objective-C Method in Objective-C within Swift to Set a Pin on the Map
        3. Bridging between Objective-C and Swift
    8. Part V: The Part of Tens
      1. Chapter 20: Ten Swift Features That Aren’t in Objective-C
        1. Using Playgrounds to Explore Code and Syntax
        2. Using Tuples
        3. Using Ranges to Save Code
        4. Taking Advantage of Strict Typing and Type Safety
        5. Initializing Your Variables and Constants
        6. Understanding Optional Types
        7. Looking at Frameworks for Your Own Code
        8. Including Annotations and Attributes in Declarations
        9. Deinitializing Variables Where Necessary
        10. Use Patterns to Simplify Your Code
      2. Chapter 21: Ten Swift Features That Are Not in C
        1. Strong Typing
        2. Libraries Extend C
        3. Switch Statements Fall through Cases in C
        4. C Is an International Standard
        5. Swift Is Tightly Linked to the Cocoa and Cocoa Touch Frameworks
        6. Swift Includes Memory Management
        7. Swift Is Designed to Function in a Multi-Threaded Environment
        8. Types Can Be Created Easily in Swift
        9. Swift Has Its Own IDE and Compiler
        10. Types Can Be Classes, Structures, or Enumerations
      3. Chapter 22: Ten Objective-C Features That Aren’t in Swift
        1. Saying Goodbye to Header (.h) Files
        2. Saying Farewell to Dangling Pointers (Almost Always)
        3. Forgetting About Uninitialized Variables and Properties
        4. Exploiting a Common Superclass Like NSObject
        5. Managing Type Casting
        6. Preferring Closures to Blocks
        7. Getting Rid of Legacy Memory Management
        8. Replacing Property Decorators
        9. Using Swift Style to Access Class Properties
        10. Clarifying Swift Access Control
    9. About the Author
    10. Author’s Acknowledgments
    11. Cheat Sheet
    12. Advertisement Page
    13. Connect with Dummies
    14. End User License Agreement

Product information

  • Title: Swift For Dummies
  • Author(s): Jesse Feiler
  • Release date: February 2015
  • Publisher(s): For Dummies
  • ISBN: 9781119022220