You are previewing Swift 3 New Features.
O'Reilly logo
Swift 3 New Features

Book Description

A fast-paced guide to get you up and running with Swift 3 and its new features

About This Book
  • Get up to date with the latest changes to Swift 3

  • Make your life easier by knowing how to port your Swift code to the latest version

  • Learn how to write programs that work on most of the major platforms such as iOS and Linux

  • Who This Book Is For

    The book is for those who are familiar with Swift but are in need of clear guidance on what’s changed in the latest version and the new features.

    What You Will Learn
  • Migrate a Swift 2.2 project to Swift 3

  • Understand the workings of Swift Package Manager

  • Interact with Cocoa libraries when importing Objective C to Swift

  • Explore the function and operator changes new in Swift 3

  • Work with the advanced type changes, attribute improvements, and floating point type improvements in Swift

  • Discover the changes in the Swift API and see how Objective-C can be manipulated in the current API

  • Implement the new features central to Swift Testing and understand the new debug features

  • Create server-side applications using Swift 3

  • In Detail

    Since Swift was introduced by Apple in WWDC 2015, it has gone on to become one of the most beloved languages to develop iOS applications with. In the new version, the Swift team aimed to take its adoption to the next level by making it available for new platforms and audiences.

    This book will very quickly get you up to speed and productive with Swift 3. You will begin by understanding the process of submitting new feature requests for future versions of Swift. Swift 3 allows you to develop and run your applications on a Linux machine. Using this feature, you will write your first Linux application using the debugger in Linux. Using Swift migrator, you will initiate a conversion from Swift 2.2 to Swift 3.

    Further on, you will learn how to interact with Cocoa libraries when importing Objective C to Swift. You will explore the function and operator changes new to Swift 3, followed by Collection and Closure changes. You will also see the changes in Swift 3 that allow you write tests easier with XCTest and debug your running code better with new formats as well. Finally, you will have a running server written completely in Swift on a Linux box.

    By the end of the book, you will know everything you need to know to dive into Swift 3 and build successful projects.

    Style and approach

    The book takes a tutorial-based approach offering an overview of the new features introduced in the latest version of Swift. It includes relevant examples of how code and concepts change when it comes to working on Swift 3 compared to previous versions.

    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 If you purchased this book elsewhere, you can visit and register to have the code file.

    Table of Contents

    1. Swift 3 New Features
      1. Swift 3 New Features
      2. Credits
      3. About the Author
      4. About the Reviewer
        1. Why subscribe?
      6. Preface
        1. Objectives and achievements 
        2. What this book covers
        3. What you need for this book
        4. Who this book is for
        5. Conventions
        6. Reader feedback
        7. Customer support
          1. Downloading the example code
          2. Errata
          3. Piracy
          4. Questions
      7. 1. What Were They Thinking?
        1. Apple's goals for Swift 3
        2. Open source Swift
        3. Contributing to Swift
        4. Swift evolution process
        5. Overview of accepted proposals for Swift 3
        6. Summary
      8. 2. Discovering New Territories – Linux at Last!
        1. Downloading Swift
        2. Swift 3 on Mac
        3. Swift 3 on Linux
        4. Using the REPL
        5. Swift Package Manager
        6. Our first Swift program
        7. Summary
      9. 3. Migrating to Swift 3 to Be More Swifty
        1. How can you migrate your project…
          1. Option1 - Migrating to Swift 3
          2. Option 2 - Migrating to Swift 2.3
        2. Planning ahead
        3. Migrating with Xcode's Swift migration tool
          1. Quick strategies for addressing issues
        4. Summary
      10. 4. Changes to Swifts Core Will Have You Asking for More
        1. The grand renaming
          1. Referencing Objective-C code in Swift 3
          2. Referencing the Objective-C selector of property getters and setters - SE-0064
            1. Referencing Objective-C key paths [SE-0062]
        2. Importing code from Objective-C and C APIs to Swift 3
          1. Importing Objective-C constants as Swift types [SE-0033]
            1. Importing as Struct
            2. Importing as Enum
          2. Importing Objective-C lightweight generics [SE-0057]
          3. Importing as member [SE-0044]
            1. Defining an initializer
            2. Creating getters and setters
            3. Adding methods
            4. Creating static variables
        3. Summary
      11. 5. Function and Operator Changes – New Ways to Get Things Done
        1. Function declaration changes
          1. Consistent parameter labeling [SE-0046]
            1. Removing currying func syntax in declaration [SE0002]
          2. Warning on Unused Results by Default [SE-0047]
            1. Removing var from function parameter lists [SE-0003]
            2. Removing ++ and -- operators [SE-0004]
            3. Removing C-style for loops [SE-0007]
            4. Removing implicit tuple splat from functions [SE-0029]
            5. Adjusting inout declarations for type decoration [SE-0031]
            6. Replacing equal signs with colons for attribute arguments [SE-0040]
            7. Standardizing function type argument syntax to require parentheses [SE-0066]
            8. Enforcing the order of defaulted parameters [SE-0060]
            9. Making optional requirements Objective-C only [SE-0070]
        2. Summary
      12. 6. Extra, Extra Collection and Closure Changes That Rock!
        1. Collection and sequence type changes
          1. Lazy FlatMap for sequence of optional [SE-0008]
          2. Adding a first(where:) method to Sequence [SE-0032]
          3. Add sequence(first: next:) and sequence(state: next:) [SE-0094]
        2. A new model for collections and indices [SE-0065]
          1. Introducing the Collection protocol
          2. Conforming to the Collection protocol
          3. New Range and associated indices types
        3. Quick takeaways
        4. Closure changes for Swift 3
          1. Limiting inout Capture of @noescape Closures [SE-0035]
          2. Resolution
          3. Making non-escaping closures the default [SE-0103]
        5. Summary
      13. 7. Hold onto Your Chair; Advanced Type Changes Are Here!
        1. Unmanaged and UnsafePointer changes
          1. Changing Unmanaged to use UnsafePointer [SE-0017]
          2. Making UnsafePointer explicit using Optional [SE-0055]
          3. Adding UnsafeRawPointer [SE-0107]
        2. Type aliases and protocol changes
          1. Generic type aliases [SE-0048]
          2. Type aliases in protocols and protocol extensions [SE-0092]
        3. Floating point changes
          1. Enhanced Floating point protocols [SE-0067]
          2. New rounding functions on the FloatingPoint protocol [SE-0113]
        4. Summary
      14. 8. Oh Goodness! Look Whats New in the Foundation Framework
        1. Mutability and Foundation value types
        2. Value types versus reference types
        3. Nested enumerations
        4. Strongly typed string enumerations
        5. Class properties
        6. Type safe access with value types
        7. Measurements and units
          1. Measurement
          2. Unit and dimension
          3. Custom units
          4. Custom Dimension types
          5. Convert functions
          6. Formatting measurements
        8. Summary
      15. 9. Improving Your Code with Xcode Server and LLDB Debugging
        1. Continuous integration overview with Xcode server
          1. Bot features
          2. Monitoring and managing bots
        2. Configuring Xcode server
          1. Adding repositories for the Xcode server
          2. Configuring bots
        3. Managing and monitoring your integration runs
        4. Debugging with LLDB
          1. LLDB command syntax
        5. Managing breakpoints
          1. Creating a breakpoint
          2. Listing breakpoints
          3. Modifying a breakpoint
          4. Enabling and disabling a breakpoint
          5. Deleting a breakpoint
          6. Command aliases
        6. Summary
      16. 10. Exploring Swift on the Server
        1. IBM Swift Package catalog
        2. Introducing our server project
          1. Project description and dependencies
          2. Setting up our environment and project
            1. The Vapor framework
            2. Routing
            3. Creating views
            4. Public resources
            5. Defining our shop view
            6. Slack integration
            7. Making a custom integration
            8. Updating our server to post to Slack
        3. Summary