Tuesday, May 12, 2015

A Simple Swift iOS App from Start to Finish - Creating an App Project in Xcode 6

Introduction


This is part of a series of articles detailing the creation of a simple iOS app. A complete list  of articles is included in the first part A Simple Swift iOS App from Start to Finish - Introduction.

I have set up a web site for the finished app at http://DaysWithoutThings.com and you can download it free directly from the app store:



My ‘Days Without Things’ app will be a universal app that will run on both iPhone and iPad and will consist of one launch screen, five views, and one data source. I’m going create it using the Swift programming language in Xcode 6.

Creating The Project

I’ll start by opening Xcode 6 and creating a new project. There are two ways to do this. I could click ‘Create a new Xcode  project’ in the launch window or I can click File - New - Project from the main menu.


Although my app will eventually have three views I will start by selecting the ‘Single View Application’ template from the iOS Application section.




After I click 'Next' I will set the product name to ‘Days Without Things’ and select 'Swift' as the language and 'Universal' as the devices type. The Organization Identifier is already filed in with my default information and I will leave it as that. I am also going to check the 'Use Core Data' option.




After I click 'Next' again I am prompted to pick a location to save my new project and given the option to create a source control repository for it. I am going to accept the option so I can track the changes I make to the project as I work through it. I will discuss how I am going to use Source Control in my next article - A Simple Swift iOS App from Start to Finish - Using Source Control in Xcode 6




After I click 'Create' I am left looking at the main Xcode window with my new project displayed in the project navigator on the left edge of the window.



Project Files

The Single View Application template creates the following files automatically:

AppDelegate.swift

This is a Swift class file that contains the definition for the AppDelegate class. This class is used to create a singleton object that is availably globally through out the app and provides  an interface to the key events in the apps executions. As I checked the Core Data option the AppDelegate also contains the code to initialize and access the apps local core data store.

ViewController.swift

This is another Swift class. It holds the code for the application's view. 

Main.storyboard

This is the project's Interface Builder file. It currently contains just the blank definition for the app's view.

Images.assets

This is a resource file that contains placeholders for the app's Icon artwork.

LaunchScreen.xib

This is an Interface Builder file that contains the definition for the default launch screen.

 Days_Without_Things.xcdatamodel

This is the app's Core Data model file.

Running the App

Before I proceed any further I’m going to test the app in the iOS emulator. To do this I select ‘iPhone 6’ from the device list and click the play button.



This opens the iOS Simulator and after a short delay opens my app within it. It uses the name of my app as the default launch screen.


Once the app finishes loading it displays its main view which is currently just a blank white screen.






As this is the first time I've run from iOS Simulator from Xcode 6 I am given a prompt to allow the Xcode app to accept incoming network connections.

To test it also works for the iPad I am going to  change the device type to ‘iPad 2’. I can then click play again and the iOS Simulator will change to displaying my app in its iPad emulation. 






Wrapping up

I have now created my project and tested that it runs.


Next:       A Simple Swift iOS App from Start to Finish - Using Source Control in Xcode 6

No comments:

Post a Comment