xCode Workshop 1 – Building First Mobile Application

So today we went about creating our first app in xC0de using swift. After a little introduction to why we were developing for the iOS operating system (e.g. 800 million devices sold, adoption of iOS at 87% compared to 7% for KitKat), we went straight into creating an application to hold and display a list of facts.

Although I was fairly positive from the last workshop, I had my doubts in building a functional app that would display data dependent on user movements. As I have personally had a iPhone for the past 4 years, I know the possibilities that the iOS holds in terms of what can be achieved so this motivated me to give it a chance and see what I can create.

Screen Shot 2015-02-06 at 15.22.32One of the main focuses was to make sure that the alignment across all devices and in multiple orientations was set to display the text and buttons within pre-set margins. Using the ‘main.storyboard’ interface to act as a guide, I was able to use constraints to make sure the text always appear in the centre across a range of devices (e.g. iPhone, iPad).

Then using an array, I set a list of random facts found on the Internet to display when a user selects ‘next’. The next stage we were set to try and work out for ourselves, was to create the ‘back’ button, and over simplifying this, I thought it would be as simple as just altering:

Screen Shot 2015-02-06 at 14.38.46




and replacing it with:

     @IBAction func previousFact() {
             currentFactIndex = (currentFactIndex-1)%facts.count

However with this method, when it reached the back of the array, the app would crash. The solution to this was to create an ‘if’ statement to say when the fact count reaches ‘0’, instead of looking for an alternative value (which does not exist), it will loop back through the sequence. This looked like:

Screen Shot 2015-02-06 at 14.47.48






Below is what I finished with at the end of the workshop:

During the workshop I found it useful to comment the code that I was working on so when I want to use similar functions in the future it can be used as a template. I think to make sure that the basic premise of what was covered was actually absorbed, I need to go over it a few times and try and create it unaided.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s