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.
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.
As shown below this works for all different variables, including integers (‘int) and booleans (‘bool’).
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:
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.