Introduction to Xcode – Swift

This week we had our first workshop on Xcode. We are going to be learning the newer language of Swift rather than Objective-C as it is a much simpler language and more up-to-date.
We started off by looking at the playground section of Xcode, so we could have a play around with the language to see how much is different to what we previously know.Screen Shot 2015-03-11 at 13.25.54


There is a fair amount of new language to learn but it is all very simple and makes logical sense, such as words just being abbreviated like above; ‘var’ is a variable, and ‘str’ is a string. However, if you declare what the variable will be, Swift will automatically detect what type of variable it is, such as below I have taken away ‘str’ and it still knows that it is a string from the type of information that has been inputted. Screen Shot 2015-03-11 at 13.54.44


As shown below this works for all different variables, including integers (‘int) and booleans (‘bool’).

Screen Shot 2015-03-11 at 14.05.25


To declare a constant you use ‘let’, constants cannot be changed but variables can be. Some other points I had not come across before are ‘?’ and ‘!’.
? = optional
! = removes the optional value

In the workshop we then went on to put the new language into practice by learning how to insert a button and get an outcome from it:

Screen Shot 2015-03-11 at 14.18.38Screen Shot 2015-03-11 at 14.19.01


When the button is pressed a label message appears on screen saying ‘Button pressed’, and we also set it to print a line in our compiler to test it is working. We also set it so that when the button is pressed 4 times, the message disappears.

From this first workshop it has made me realise all the possibilities and also how it can be very simple to create something very effective. This has made be very excited for upcoming workshops and to get started on the project. Next workshop we will be putting our knowledge into practice by making a simple random facts app.