O'Reilly logo

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Swift by Example

Book Description

Create funky, impressive applications using Swift

In Detail

When Apple announced Swift at the WWDC, the iOS developer community became excited about the opportunities to improve the way in which they build iOS apps. Swift is a user-friendly language with a smooth learning curve; it is safe, robust, and flexible, and it introduces new ways to solve old problems.

Swift by Example is a fast-paced, practical guide that shows you how to develop iOS apps using Swift. Through the development of six different apps, you'll learn how to use either the right feature of the language or the right tool to solve a given problem.

By the end of the book you will be able to build well-designed apps, effectively use AutoLayout, and develop a video game.

What You Will Learn

  • Explore the features of Swift
  • Connect to a server and parse JSON data
  • Take advantage of CocoaPods to use third-party libraries
  • Utilize a clean and effective architecture to decrease complexity and speed up development
  • Work with the most useful parts of the iOS SDK
  • Build video games with SpriteKit and SceneKit
  • Develop apps from start to finish
  • Implement a weather app using fake data

Table of Contents

  1. Swift by Example
    1. Table of Contents
    2. Swift by Example
    3. Credits
    4. About the Author
    5. About the Reviewers
    6. www.PacktPub.com
      1. Support files, eBooks, discount offers, and more
        1. Why subscribe?
        2. Free access for Packt account holders
    7. Preface
      1. What this book covers
      2. What you need for this book
      3. Who this book is for
      4. Conventions
      5. Reader feedback
      6. Customer support
        1. Downloading the example code
        2. Errata
        3. Piracy
        4. Questions
    8. 1. Welcome to the World of Swift
      1. The first look at Swift
        1. Let's go to the playground
        2. The building blocks – variables and constants
        3. Collect variables in containers
        4. Controlling the flow
        5. Transforming the values using functions
        6. Structs – custom compounds type
        7. Classes – common behavior objects
        8. Loose coupling with protocols
        9. Check the existence of an optionals value
        10. Enumerations on steroids
      2. A Guess the Number app in Swift
        1. The app is…
        2. Building a skeleton app
        3. Adding the graphic components
        4. Connecting the dots
        5. Adding the code
        6. Summary
    9. 2. A Memory Game in Swift
      1. The app is…
      2. Building the skeleton of the app
      3. The menu screen
        1. Implementing the basic menu screen
        2. Creating a nice menu screen
      4. The game screen
        1. The structure
        2. Adding the collectionView class
        3. Sizing the components
        4. Connecting the datasource and the delegate
      5. Implementing a deck of cards
        1. What we are expecting
        2. The Card entity
        3. Crafting the deck
        4. Shuffling the deck
        5. Finishing the deck
      6. Put the cards on the table
        1. Adding the assets
        2. The CardCell structure
        3. Handling touches
      7. Finishing the game
        1. Implementing the game logic
        2. We got a pair
        3. We played a wrong turn
        4. Et voilà! The game is completed
      8. Summary
    10. 3. A TodoList App in Swift
      1. The app is…
      2. Building a skeleton app
        1. Implementing an empty app
        2. Adding third-party libraries with CocoaPods
        3. Implementing the Todos ViewController
      3. Building the Todos screen
        1. Adding the entities
        2. Implementing the datastore
        3. Connecting the datastore and the ViewController
        4. Configuring tableView
        5. Implementing TodoViewCell
        6. Swipe that cell!
      4. Adding a Todo task
        1. The add a Todo ViewController
        2. Updating the datastore
      5. Adding a list
        1. Implementing ListViewCell
        2. Building ListViewController
        3. Updating the datastore
      6. Where do we go from here?
      7. Summary
    11. 4. A Pretty Weather App
      1. The app is…
      2. Building the skeleton
        1. Creating the project
        2. Adding the assets
      3. Implementing the UI
        1. The UI in blocks
      4. Completing the UI
        1. CurrentWeatherView
        2. WeatherHourlyForecastView
        3. WeatherDaysForecastView
      5. Blurring the background
      6. Downloading the background image
        1. Searching in Flickr
      7. Geolocalising the app
        1. Using CoreLocation
      8. Retrieving the actual forecast
        1. Getting the forecast from OpenWeatherMap
        2. Rendering CurrentWeatherView
        3. Rendering WeatherHourlyForecastView
        4. Rendering WeatherDaysForecastView
      9. Connecting to the server
      10. Where do we go from here?
      11. Summary
    12. 5. Flappy Swift
      1. The app is…
      2. Building the skeleton of the app
        1. Creating the project
        2. Implementing the menu
      3. A stage for a bird
        1. SpriteKit in a nutshell
        2. Explaining the code
        3. Simulating a three-dimensional world using parallax
        4. How to implement the scrolling
      4. A flying bird
        1. Adding the Bird node
        2. Making the bird flap
      5. Pipes!
        1. Implementing the pipes node
      6. Making the components interact
        1. Setting up the collision detection engine
      7. Completing the game
        1. Colliding with the pipes
        2. Adding the score
        3. Adding a restarting popup
      8. Summary
    13. 6. Polishing Flappy Swift
      1. Adding juiciness
        1. Let there be sounds!
        2. Playing the soundtrack
        3. Shaking the screen!
      2. Integrating with Game Center
        1. What Game Center provides
        2. Setting up Game Center
        3. Creating an app record on iTunes Connect
        4. Enabling Game Center
        5. Creating fake user accounts to test Game Center
        6. Authenticating a player
      3. Summary
    14. 7. Cube Runner
      1. The app is…
      2. Introduction to SceneKit
        1. What is SceneKit?
        2. Building an empty scene
        3. Adding a green torus
        4. Let there be light!
        5. Let's make it move!
      3. Implementing Cube Runner
        1. The game skeleton
        2. Implementing the menu
      4. Flying in a 3D world
        1. Setting up the scene
        2. Adding the fighter
        3. Texturing the world
        4. Make it move
        5. Adding the cubes
        6. Adding more obstacles
      5. Adding a few touches
        1. The score
        2. Let's add the music
      6. Summary
    15. 8. Completing Cube Runner
      1. Making it a real game
        1. Detecting collisions
        2. Game Over!
        3. Adding the juice
        4. Game Center
      2. Summary
    16. Index