You are previewing Swift Essentials.
O'Reilly logo
Swift Essentials

Book Description

Get up and running lightning fast with this practical guide to building applications with Swift

In Detail

Swift is a new and powerful programming language that represents an essential new programming tool for iOS and OSX applications and builds upon the power of Objective-C while streamlining the developer experience.

Swift Essentials is a fast-paced, practical guide showing you the quickest way to put Swift to work in the real world. It guides you concisely through the basics of syntax and development before pushing ahead to explore Swift's higher features through practical programming projects.

By the end of the book, you will be able to use Xcode's graphical interface builder, create interactive applications, and communicate with network services.

What You Will Learn

  • Explore the nuts and bolts of the Swift syntax
  • Test Swift code interactively with the REPL
  • Display graphics with QuickLook in the Swift playground
  • Present data in master-detail applications
  • Use the Swift storyboard to manage multi-screen applications
  • Create graphical UIViews with Swift
  • Parse JSON and XML data from network sources
  • Build a standalone iOS application from start to finish
  • Downloading the example code for this book. You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

    Table of Contents

    1. Swift Essentials
      1. Table of Contents
      2. Swift Essentials
      3. Credits
      4. About the Author
      5. Acknowledgments
      6. About the Reviewers
      7. www.PacktPub.com
        1. Support files, eBooks, discount offers, and more
          1. Why subscribe?
          2. Free access for Packt account holders
      8. Preface
        1. What this book covers
        2. What you need for this book
        3. Who this book is for
        4. Trademarks
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      9. 1. Exploring Swift
        1. Getting started with Swift
          1. Numeric literals
          2. Floating point literals
          3. String literals
          4. Variables and constants
          5. Collection types
          6. Optional types
          7. Nil coalescing operator
        2. Conditional logic
          1. If statements
          2. Switch statements
        3. Iteration
          1. Iterating over keys and values in a dictionary
          2. Iteration with for loops
          3. Break and continue
        4. Functions
          1. Named arguments
          2. Optional arguments and default values
          3. Anonymous arguments
          4. Multiple return values and arguments
          5. Returning structured values
        5. Command-line Swift
          1. Interpreted Swift scripts
          2. Compiled Swift scripts
        6. Summary
      10. 2. Playing with Swift
        1. Getting started with playgrounds
          1. Creating a playground
          2. Viewing the console output
          3. Viewing the timeline
        2. Displaying objects with QuickLook
          1. Showing colored labels
          2. Showing images
        3. Advanced techniques
          1. Capturing values explicitly
          2. Running asynchronous code
        4. Playgrounds and documentation
          1. Learning with playgrounds
          2. Understanding the playground format
          3. Adding a new documentation section
          4. Styling the documentation
          5. Adding resources to a playground
          6. Additional entries in the header
          7. Generating playgrounds automatically
            1. Markdown
            2. AsciiDoc
        5. Limitations of playgrounds
        6. Summary
      11. 3. Creating an iOS Swift App
        1. Understanding iOS applications
        2. Creating a single view iOS application
          1. Removing the storyboard
          2. Setting up the view controller
        3. Swift classes, protocols, and enums
          1. Classes in Swift
          2. Subclasses and testing in Swift
          3. Protocols in Swift
          4. Enums in Swift
            1. Raw values
            2. Associated values
        4. Creating a master-detail iOS application
          1. The AppDelegate class
          2. The MasterViewController class
          3. The DetailViewController class
        5. Summary
      12. 4. Storyboard Applications with Swift and iOS
        1. Storyboards, scenes, and segues
          1. Creating a storyboard project
          2. Scenes and view controllers
          3. Adding views to the scene
          4. Segues
        2. Adding a navigation controller
          1. Naming scenes and views
        3. Swift and storyboards
          1. Custom view controllers
          2. Connecting views to outlets in Swift
          3. Calling actions from interface builder
          4. Triggering a segue with code
          5. Passing data with segues
        4. Using Auto Layout
          1. Understanding constraints
          2. Adding constraints
            1. Adding a constraint with the drag and drop method
            2. Adding constraints to the Press Me scene
            3. Adding missing constraints
        5. Summary
      13. 5. Creating Custom Views in Swift
        1. An overview of UIView
        2. Creating new views with interface builder
          1. Creating a table view controller
          2. Showing data in the table
          3. Defining a view in a XIB file
          4. Wiring a custom view class
          5. Dealing with intrinsic size
        3. Creating views by subclassing UIView
          1. Auto Layout and custom views
          2. Constraints and the visual format language
          3. Adding the custom view to the table
        4. Custom graphics with drawRect
          1. Drawing graphics in drawRect
          2. Responding to orientation changes
        5. Custom graphics with layers
          1. Creating a ProgressView from layers
          2. Adding the stop square
          3. Adding a progress bar
          4. Clipping the view
          5. Testing views in Xcode
          6. Responding to change
        6. Summary
      14. 6. Parsing Networked Data
        1. Loading data from URLs
          1. Dealing with errors
          2. Dealing with missing content
          3. Nested if and switch statements
          4. Networking and user interfaces
          5. Running functions on the main thread
        2. Parsing JSON
          1. Handling errors
        3. Parsing XML
          1. Creating a parser delegate
          2. Downloading the data
          3. Parsing the data
        4. Direct network connections
          1. Opening a stream connection
          2. Synchronous reading and writing
            1. Writing data to an NSOutputStream
            2. Reading from an NSInputStream
            3. Reading and writing hexadecimal and UTF8 data
            4. Implementing the git protocol
            5. Listing git references remotely
            6. Integrating the network call into the UI
          3. Asynchronous reading and writing
            1. Reading data asynchronously from an NSInputStream
            2. Creating a stream delegate
            3. Dealing with errors
            4. Listing references asynchronously
            5. Displaying asynchronous references in the UI
            6. Writing data asynchronously to an NSOutputStream
        5. Summary
      15. 7. Building a Repository Browser
        1. An overview of the GitHub API
          1. The root endpoint
          2. The user resource
          3. The repositories resource
        2. The RepositoryBrowser project
          1. URI templates
          2. Background threading
          3. Parsing JSON dictionaries
          4. Parsing JSON arrays of dictionaries
        3. Creating the client
          1. Talking to the GitHub API
          2. Returning repositories for a user
          3. Accessing data through the AppDelegate
        4. Accessing repositories from view controllers
          1. Adding users
          2. Implementing the detail view
          3. Transitioning between the master and detail views
          4. Loading the user's avatar
          5. Displaying the user's avatar
        5. Summary
      16. A. Appendix
        1. Language
        2. Twitter users
        3. Blogs and tutorial sites
        4. Meetups
        5. Afterword
      17. Index