Essay on Using Variables For The Purpose Of Storing Values

1352 Words Aug 26th, 2015 6 Pages
For programming to be effective, then one has to use variables for the purpose of storing values. Variables just mean a memory location which has been reserved. However, you need to know that variables are of various data types, and this means that different amounts of memory spaces are reserved for them. In Swift the basic data types which are supported include, Integers, double, float, characters, string, Boolean and Optional.
Type Aliases
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.
Type Safety
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…

Related Documents