Creating and Running Your iOS App

⇦ Aligning Parallax Barrier    HOME    Rendering Light Field ⇨

Your hardware is ready, and now it’s time to build some software to test it out! In this step we will get up and running with the default iOS Game template, based on SceneKit. Get started by launching Xcode on your Mac.

Xcode Launch Screen

Choose to “Create a new Xcode Project”.

Template Chooser

In the template chooser, in the iOS Application section, choose “Game”.

New Project

Give your project a name and a unique identifier based on your name or your organization’s name. If you have a web domain, using reverse-domain notation is the convention. Use Swift and SceneKit. For this tutorial, we will focus on iPhone, so choose that option. Feel free to generate tests for your project, but we won’t be discussing them here.

In the next window, choose a location to save your project. You can check the box to initialize a Git repository if you want.

Created Files

Once your project is loaded, you will see that Xcode has created several files for you. Let’s go over them.

  1. AppDelegate.swift: This class is responsible for managing the lifetime of your application. We won’t be touching it in this tutorial, but you would put code here to respond to the events that are well documented in the file.
  2. art.scnassets: This is a folder containing the test 3D model we will use to render our light field.
  3. GameViewController.swift: This is where we will put the majority of our code. A view controller is responsible for controlling what is displayed on the screen.
  4. Main.storyboard: This file defines the layout of our user interface. By default it is just a single view where our content is rendered, and we will leave it as is.
  5. Assets.xcassets: This folder contains icon images for your app.
  6. LaunchScreen.storyboard: This file defines the look of your launch screen.
  7. Info.plist: This file defines several properties of your application. We won’t need to adjust these.

Take a closer look at GameViewController.swift. In the viewDidLoad() function, a new scene is loaded from file:

    // create a new scene
    let scene = SCNScene(named: "art.scnassets/ship.scn")!

A camera and some lights are created, and the ship model’s properties are adjusted. Finally, the scene is assigned to the current view so it will be rendered.

    // retrieve the SCNView
    let scnView = self.view as! SCNView

    // set the scene to the view
    scnView.scene = scene

Make sure the scheme selector in the upper left-hand corner is set to a valid simulator and click the Run button.

Scheme Selector

You should see an iOS simulator launch and render a spinning space ship.


As of this writing, the Xcode simulator only supports OpenGL ES 3D graphics. For this tutorial, we will be using the iOS Metal API for dramatically better performance. This means that in order to test your app, you will need to attach a real device.

Plug your iPhone in to your Mac and select it in the scheme selector.

Screen Shot 2016-03-12 at 9.31.44 PM

It may say that it is loading symbols; you will have to wait for this process to complete before you continue.

Click the Run button. At this point, if you have never deployed an app to this device before, it will ask you to fix code signing issues. Unless you know better, choose to sign the app using your personal team—this is a developer account that you get for free to develop and deploy apps on your personal devices. It is tied to your Apple ID.

Once the app has been copied to your device, you will need to choose to trust the app on your iPhone by navigating to Settings > General > Profiles & Device Management.

Profiles & Device Management

You should now be able to run the app on your phone and see the spinning ship. Congratulations!

The next step is to render your light field.

Comments are closed.