iOS 11 Swift Programming Cookbook

Book description

iOS 11, Swift 4, and Xcode 9 provide many new APIs for iOS developers. With this cookbook, you’ll learn more than 170 proven solutions for tackling the latest features in iOS 11 and watchOS 4, including new ways to use Swift and Xcode to make your day-to-day app development life easier. This collection of code-rich recipes also gets you up to speed on continuous delivery and continuous integration systems.

Ideal for intermediate and advanced iOS developers looking to work with the newest version of iOS, these recipes include reusable code on GitHub, so you can put them to work in your project right away.

Among the topics covered in this book:

  • New features in Swift 4 and Xcode 9
  • Tools for continuous delivery and continuous integration
  • Snapshot testing and test automation
  • Creating document-based applications
  • Updated Map view and Core Location features
  • iOS 11’s Security and Password Autofill
  • Data storage with Apple’s Core Data
  • Creating lively user interfaces with UI Dynamics
  • Building iMessage applications and sticker packages
  • Integrating Siri into your apps with Siri Kit
  • Creating fascinating apps for Apple Watch

Publisher resources

View/Submit Errata

Table of contents

  1. Preface
    1. Audience
    2. Organization of This Book
    3. Conventions Used in This Book
    4. Additional Resources
    5. Using Code Examples
    6. O’Reilly Safari
    7. How to Contact Us
    8. Acknowledgments
  2. Continuous Integration and Delivery
    1. 1.1. Setting Up Xcode Server
    2. 1.2. Connecting Local Xcode to Xcode Server
    3. 1.3. Archiving Your Apps with Xcode Bots
    4. 1.4. Running Your Tests Automatically with Xcode Bots
    5. 1.5. Performing Analysis of Your Code Using Xcode Bots
    6. 1.6. Integrating GitHub Projects with Travis
    7. 1.7. Installing the Travis CLI
    8. 1.8. Running Your Unit Tests with Travis
    9. 1.9. Building and Archiving Your Project with Travis
    10. 1.10. Installing and Setting Up fastlane
    11. 1.11. Building Your Apps with fastlane
    12. 1.12. Testing Your Apps with fastlane
    13. 1.13. Enabling Slack Notifications in fastlane
    14. 1.14. Archiving Your Apps with fastlane
    15. 1.15. Uploading Your Apps to iTunes Connect with fastlane
  3. Snapshot Testing
    1. 2.1. Setting Up Snapshot Testing
    2. 2.2. Recording Snapshots
    3. 2.3. Specifying Tolerance in Snapshot Tests
    4. 2.4. Analyzing Snapshot Test Case Failures
    5. 2.5. Testing Table View Cell Snapshots
  4. SiriKit
    1. 3.1. Setting Up Your Project for Siri
    2. 3.2. Defining an Intent Handler
    3. 3.3. Resolving Ambiguity in an Intent
    4. 3.4. Reporting Progress for Resolving an Intent
    5. 3.5. Handling an Intent
  5. Measurements and Units
    1. 4.1. Converting Between and Working with Length Units
    2. 4.2. Working with and Switching Between Angle Units
    3. 4.3. Representing and Converting Between Durations of Time
    4. 4.4. Using and Working with Frequency Units
    5. 4.5. Working with and Using Power Units
    6. 4.6. Representing and Comparing Temperature Units
    7. 4.7. Working with and Converting Volume Units
  6. Core Data
    1. 5.1. Designing Your Database Scheme
    2. 5.2. Writing Data to the Database
    3. 5.3. Reading Data from the Database
    4. 5.4. Searching for Data in the Database
    5. 5.5. Performing Background Tasks with Core Data
  7. Swift and Cocoa Touch
    1. 6.1. Extending Typed Arrays
    2. 6.2. Taking Advantage of Open Collection Ranges
    3. 6.3. Organizing Private Functions and Properties with Extensions
    4. 6.4. Defining Key Paths in Swift
    5. 6.5. Parsing from and to JSON with Swift
    6. 6.6. Handling Corner Cases in JSON Parsing with Swift
    7. 6.7. Partitioning Arrays into Segments
    8. 6.8. Setting Constraints on Extensions
    9. 6.9. Defining Object Requirements Through Protocols
    10. 6.10. Creating New Data Types by Combination
    11. 6.11. Adding Logic Through Protocols
    12. 6.12. Defining Constraints on Protocols
    13. 6.13. Handling Errors in Swift
    14. 6.14. Specifying Preconditions for Methods
    15. 6.15. Ensuring the Execution of Code Blocks Before Exiting Methods
    16. 6.16. Checking for API Availability
    17. 6.17. Creating Your Own Set Types
    18. 6.18. Conditionally Extending a Type
    19. 6.19. Optimizing Your Swift Code
    20. 6.20. Building Equality Functionality into Your Own Types
    21. 6.21. Grouping switch Statement Cases Together
    22. 6.22. Looping Conditionally Through a Collection
    23. 6.23. Bundling and Reading Data in Your Apps
  8. Xcode 9 and Interface Builder
    1. 7.1. Changing Variable Names in the Current Scope
    2. 7.2. Utilizing Regular Expressions in Your Xcode Searches
    3. 7.3. Debugging Apps on an iOS Device Wirelessly
    4. 7.4. Making Sure UI Methods Run on the Main Thread
    5. 7.5. Creating a GitHub Repository for Your Project in Xcode
    6. 7.6. Synchronizing Your Code with GitHub Inside Xcode
    7. 7.7. Categorizing and Downloading Assets to Get Smaller Binaries
    8. 7.8. Exporting Device-Specific Binaries
    9. 7.9. Linking Separate Storyboards Together
    10. 7.10. Adding Multiple Buttons to the Navigation Bar
    11. 7.11. Showing the Header View of Your Swift Classes
    12. 7.12. Designing Interactive Interface Objects in Playgrounds
  9. The User Interface
    1. 8.1. Animating Details with Peek and Pop
    2. 8.2. Providing Dynamic 3D Touch Menus on Home Screen
    3. 8.3. Asking Your Users for App Store Reviews in Your App
    4. 8.4. Providing Vibrational Feedback to Users
    5. 8.5. Supporting Drag and Drop in Your Apps
    6. 8.6. Scaling Fonts in Order to Support Dynamic Types
    7. 8.7. Adjusting Labels While Supporting Dynamic Types
    8. 8.8. Extracting Named Colors from Asset Catalogs
    9. 8.9. Animating Views
    10. 8.10. Attaching Live Views to Playgrounds
    11. 8.11. Running Playgrounds as Interactive and Continuous Apps
    12. 8.12. Arranging Your Components Horizontally or Vertically
    13. 8.13. Customizing Stack Views for Different Screen Sizes
    14. 8.14. Creating Anchored Constraints in Code
    15. 8.15. Allowing Users to Enter Text in Response to Local and Remote Notifications
    16. 8.16. Dealing with Stacked Views in Code
    17. 8.17. Showing Web Content in Safari View Controller
    18. 8.18. Laying Out Text-Based Content on Your Views
    19. 8.19. Improving Touch Rates for Smoother UI Interactions
    20. 8.20. Supporting Right-to-Left Languages
    21. 8.21. Associating Keyboard Shortcuts with View Controllers
    22. 8.22. Recording the Screen and Sharing the Video
  10. Document-Based Apps
    1. 9.1. Supporting File Browsing in Your App
    2. 9.2. Associating File Types with Your App
    3. 9.3. Creating New Documents
    4. 9.4. Saving Your Documents
    5. 9.5. Loading Existing Documents
    6. 9.6. Customizing Your Document Browser
  11. Apple Watch
    1. 10.1. Downloading Files onto the Apple Watch
    2. 10.2. Noticing Changes in Pairing State Between the iOS and Watch Apps
    3. 10.3. Transferring Small Pieces of Data to and from the Watch
    4. 10.4. Transferring Dictionaries in Queues to and from the Watch
    5. 10.5. Transferring Files to and from the Watch
    6. 10.6. Communicating Interactively Between iOS and watchOS
    7. 10.7. Setting Up the Apple Watch for Custom Complications
    8. 10.8. Constructing Small Complications with Text and Images
    9. 10.9. Displaying Time Offsets in Complications
    10. 10.10. Displaying Dates in Complications
    11. 10.11. Displaying Times in Complications
    12. 10.12. Displaying Time Intervals in Complications
    13. 10.13. Recording Audio in Your Watch App
    14. 10.14. Playing Local and Remote Audio and Video in Your Watch App
  12. Contacts
    1. 11.1. Creating Contacts
    2. 11.2. Searching for Contacts
    3. 11.3. Updating Contacts
    4. 11.4. Deleting Contacts
    5. 11.5. Formatting Contact Data
    6. 11.6. Picking Contacts with a Prebuilt System UI
    7. 11.7. Creating Contacts with a Prebuilt System UI
    8. 11.8. Displaying Contacts with a Prebuilt System UI
  13. Extensions
    1. 12.1. Creating Safari Content Blockers
    2. 12.2. Creating Shared Links for Safari
    3. 12.3. Maintaining Your App’s Indexed Content
  14. Web and Search
    1. 13.1. Continuing a Spotlight Search Within Your App
    2. 13.2. Making Your App’s Content Searchable
    3. 13.3. Making User Activities Searchable
    4. 13.4. Deleting Your App’s Searchable Content
  15. Multitasking
    1. 14.1. Supporting Split Views
    2. 14.2. Adding Picture in Picture Playback Functionality
    3. 14.3. Handling Low Power Mode and Providing Alternatives
  16. Maps and Location
    1. 15.1. Customizing the Map View with System Buttons
    2. 15.2. Displaying System Annotations on the Map
    3. 15.3. Clustering Annotations for a Clutter-Free Map
    4. 15.4. Displaying a Specific Location on the Map
    5. 15.5. Requesting the User’s Location a Single Time
    6. 15.6. Requesting the User’s Location in the Background
    7. 15.7. Customizing the Tint Color of Pins on the Map
    8. 15.8. Providing Detailed Pin Information with Custom Views
    9. 15.9. Displaying Traffic, Scale, and Compass Indicators on the Map
    10. 15.10. Providing an ETA for Transit Transport Type
    11. 15.11. Launching the iOS Maps App in Transit Mode
    12. 15.12. Showing Maps in Flyover Mode
  17. UI Testing
    1. 16.1. Preparing Your Project for UI Testing
    2. 16.2. Automating UI Test Scripts
    3. 16.3. Testing Text Fields, Buttons, and Labels
    4. 16.4. Finding UI Components
    5. 16.5. Long-Pressing on UI Elements
    6. 16.6. Typing Inside Text Fields
    7. 16.7. Swiping on UI Elements
    8. 16.8. Tapping UI Elements
  18. Core Motion
    1. 17.1. Querying Pace and Cadence Information
    2. 17.2. Recording and Reading Accelerometer Data
  19. Security
    1. 18.1. Supporting Password Autofill with iCloud Keychain
    2. 18.2. Protecting Your Network Connections with ATS
    3. 18.3. Binding Keychain Items to Passcode and Touch ID
    4. 18.4. Opening URLs Safely
    5. 18.5. Authenticating the User with Touch ID and Timeout
  20. Multimedia
    1. 19.1. Reading Out Text with the Default Siri Alex Voice
    2. 19.2. Downloading and Preparing Remote Media for Playback
    3. 19.3. Enabling Spoken Audio Sessions
  21. UI Dynamics
    1. 20.1. Adding a Radial Gravity Field to Your UI
    2. 20.2. Creating a Linear Gravity Field on Your UI
    3. 20.3. Creating Turbulence Effects with Animations
    4. 20.4. Adding Animated Noise Effects to Your UI
    5. 20.5. Creating a Magnetic Effect Between UI Components
    6. 20.6. Designing a Velocity Field on Your UI
    7. 20.7. Handling Collisions Between Nonrectangular Views
  22. iMessage Stickers and Apps
    1. 21.1. Setting Up a Sticker Pack Application
    2. 21.2. Adjusting Sticker Sizes
    3. 21.3. Building a Full-Fledged iMessage Application
    4. 21.4. Adding an iMessage App Extension to an Existing App
    5. 21.5. Utilizing an Expanded View in a Sticker Pack App
    6. 21.6. Appending Rich Information to Stickers
    7. 21.7. Creating Interactive Conversations with iMessage Apps
  23. Index

Product information

  • Title: iOS 11 Swift Programming Cookbook
  • Author(s): Vandad Nahavandipoor
  • Release date: December 2017
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491992470