As all developers related to IOS and mac OS X app development are aware of the fact that Apple launched new programming language to develop IOS and mac OS X apps. This new programming language is named as SWIFT. In this post we will cover basic part of the language.
Constants and Variables:
As the terms are self explanatory, constant refer to the values which never changed during the life of algorithm or during runtime, whereas variables refers to the values which can be changed during runtime or life of our program. The value of constant cannot be changed once set whereas variable are totally opposite to constant.
Declaring constant and variable:
Thumb rule of programming is that you have to declare variables/objects before using them in your program. In SWIFT you can declare constant using let keyword and variable using var keyword. Let us take an example, we will create a constant for maximum number of lives player had in a game and a variable to keep track of live used by the player in a game.
let maximumNumberofLives = 5;
var currentLive = 0;
let maximumNumberofLives = 5.0;
var currentLive = 0.0;
var x = 0,y = 0,z = 0;
let x = 0,y = 0,z = 0;
var message: String
welcomeMessage = "Welcome to Swift Language";
println("This is a string");
println("The current value of friendlyWelcome is (welcomeMessage)");