Introduction to Ios

Published March 09, 2022

To get started with iOS development , one of the important  things you need to know id the programming language used in iOS development , there are two programming languages you can use to develop iOS applications , Swift and Objective-C .

What is Swift ?

Swift is a powerful and intuitive programming language developed by Apple Inc. for iOS, IPadOs, macOS, tvOS and watchOS. Swift is said to be faster , modern and easier to learn than Objective-C.

 

What is Objective-C ?

Objective-C is a general purpose , object oriented programming language that adds Smaltalk-style messaging to the C programming language , but most important here , it can be used for iOS development .

 

Why Swift ?

After knowing the definition of swift and Objective-C , the next question that will come to mind is why swift ?. Truly Objective-C has more functions than Swift , but Objective is over thirty years old , and that means it has a more clunky syntax . Unlike Swift , Objective-C requires more code and it’s verbose when it comes to string manipulation and on other hand , swift employs string interpolation,  without placeholders or tokens.


Swift Logo Swift

One of the basic things you will have to learn in any modern programming language is its data types , swift has four data types namely : Strings , Integers , Float and Double.

 

String : One of the ways you can identify a string in swift is when you find a piece of text un between punctuation marks. 

 

“Mother”, “Father”, “Boy”, “Girl”

//These are examples of the String data type

 

Integers : This Is another data type , but unlike strings they don’t need to be in punctuation marks , instead , they are  numbers from 1 - 0  . 

1, 2, 3 ,4, 5, 6, 7, 8, 9, 0

//These are examples of the integer data type

 

Float :  Swift provides two point floating numbers , Float represents a 32-bit floating-point 

number.
 

Double : The second floating point number is Double , Double represents a 64-bit floating-point number.

 

Now, we have learnt  the four data types in swift , another necessity we need to know in Swift is how to create Variables, constants , Arrays, dictionaries, Tuples, sets and enums .

 

Variables :  Whenever a program is built , a certain data will has to be saved , whether its the user’s name , or some downloaded data , in swift , this is done in two ways either by variables or constants , but for now we will only be talking about variables .  To create a variable is no issue at all , you can create one by simply writing the  var  keyword , followed by the name we will like to give our variable  username  followed by an equals sign to assign our custom value to our variable. So our variable will look something like this :

var username = “Tim”

 

Constants : The second way to save data In swift is called constants , similar to variables , constants also uses an initializer keyword but Instead of var, constant uses let keyword also followed by the name we will like to give our constant username, followed by an equal sign to assign our custom value to our constant . Our constant will look something like this :

let username = "Tim"


 

//This are the two types of ways to save data in swift , they have enough in common for you to think they are exactly the same and have the same functions, but they are differences between Variables and Constants , one of them is that the value of a  variable can be altered anywhere in the code while that of constant cannot be altered.

 

var username = "Tim"

username = "Ben"

    // We are altering the value "Tim" in the variable and changing it to “Ben"

 

This is acceptable in swift as long as this is a variable , but is not acceptable if this is a constant .

 

let username = "Tim"

username = "Ben"

    // We are altering the value "Tim" in the variable and changing it to “Ben”

This is an invalid swift code because we cannot alternate the value of a constant , so this piece of code will not run.

Arrays :  In other words , you can say an array is a set or a list of a certain data type , it is also a necessity In swift ,  it main purpose is to store multiple data together at once . An array has a similar way of creation to variables and constants , a var keyword is written at first , followed by a name to call our array companies then an equals sign and our strings . Our Array will look something like this :

 

var companies = ["Apple", "Meta", "Google", "Amazon", "Spotify", “Netflix"]

 

Dictionaries : Just like arrays , dictionary is also a way of sorting data in a singular variable , the only difference between them is the way the datas are stored , unlike arrays , we have to chose a key that acts as an identifier for the item we will like to add , because of this we don’t have to remember a certain index to a certain item on the array , instead, it will be something like this  Device[“Apple”] , Device is the key in the case of this dictionary and Apple is the item we will like to add, it os way more easier than typing an array and trying to remember the index of the array every time you want to call the saved item
 

Tuples : This is another means of storing data , it basically allows you to store several values in a single , creating them is simple var name = (first: "Tim", last: “Cook") , they can be accessed  like arrays  value and unlike dictionaries, tuples have a little more difference than dictionaries they are ,

  • Tuples cannot be altered , which means items cannot be added or removed form tuples , unlike a dictionary and array that items can be removed from them and can be added to them.

  • The type of data you use in a tuple cannot be changed throughout the tuple 


Enums / Enumerations : This is a way of easing our work by defining groups of related values , it handle a little more complex tasks than others than we have mentioned so far