Essay on Using Variables For The Purpose Of Storing Values
One can use the “typealias” so as to create a new name for a type which already exists. Consider the example given below which shows how a simple alias can nbe created in Swift: typealias aliasname = type
Suppose that you want to assign a new name to the “Int” data type. This can be done as shown below: typealias MyData = Int
In the above case, we have just told the compiler that “MyData” is the other name for “Int”. Consider the next example which is given below: import Cocoa typealias MyData = Int var age: MyData = 34 println(age) Just write the above program as it is and then run it. The following output should be observed from it: The output just shows the value of the variable “age” which of “MyData” data type. This is just an integer as we had instructed the compiler.
With Swift programming language, type safety is very essential. This means that if a particular section of the code is expecting an integer to be passed, then you can’t pass a String in place of the integer.
The process of type checking in Swift is…