Building my first iOS app with Swift 2.0: Session I

Even though I have been a software engineer for a very long time, never having owned an iPhone, I never got interested in learning iOS development. I plan to change that over the next few days.

The goal is to create an iOS app for what I prototyped here using the Ionic framework. Ionic is an excellent way to get started with creating hybrid apps using AngularJS. It also includes Cordova (formerly PhoneGap) provides the glue to turn the app native for iOS and Androd.

Image for post
Image for post
Target App — My Idea List. Inspiration can strike anywhere. The app provides a simple way to capture your creative ideas on the go.

Session I

In this first session, I got familiar with Swift using a few online tutorials from Pluralsight. All my Swift learning is here on GitHub. I started with whatever version of Xcode & Swift I had, and after a few exercises realized that Swift 2.0 has been out since a few months ago.

Next, let’s get a little more ‘appy.

I. Creating the UI

A ‘Scene’ are what you see on the “screen” — a collection of all the UI elements you see on the screen. I believe my target app will have at least 4 scenes:

  1. The ‘Home’ screen with the list of ideas sorted in some order.
  2. The ‘Details’ screen for an idea.
  3. The ‘Capture a new idea” screen
  4. The ‘About this App’ screen.

Created a new Xcode project: A ‘Single View Application’.

Image for post
Image for post
Creating your new project in Xcode. Make sure the language is Swift and I will control my ambition to only make this for the iPhone.

“Storyboard” the views: It’s exactly what it sounds like — You create View Controllers and add the View elements (e.g. Table View) to the controllers which are individual screens.

I sized every view to iPhone 4.7-inch — apparently that’s what is iPhone 6.

Image for post
Image for post
My 4 scenes, all manually sized to 4.7-inch and a Table View added to the first View Controller.

Creating Segues: The transitions where you move from one scene to another scene.

I needed to do a couple of things to make our first scene “active”. After selecting the Table View and using the “Interface Builder”, I added a dataSource and a delegate to the View Controller. It’s some drag and drop magic.

Image for post
Image for post

Next, linking some static data to show up in this TableView

Now we are getting into some real code. The ViewController needs to implement a couple of TableView methods that does the following

  1. Returns how many elements are in the table
  2. Returns the cell that needs to be displayed

Note: The ViewController by default inherits from UIViewController. The first thing I did was to change this into a UITableViewController.

Image for post
Image for post
My ViewController that implements tableView methods and should display the elements defined in the static array.

And Voilà! we have display.

The controller code above should have produced a working app. But I kept getting this runtime error when running the simulator. After some futzing around looking for what I can delete, I have liftoff.

Image for post
Image for post
My Idea List app so far displays a list from a static array.

There we have it. I will call this an end to Session I. I am not sure how many more sessions to go before I get to a working app that could even be a candidate to make it into the AppStore, but if you would like to follow long, I will have the code on GitHub.

Written by

Co-founder & CTO at @ilovemaxwell. Previously founded @brightfunds. http://rutuldave.com

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store