Last active
August 29, 2015 14:17
-
-
Save astronomersiva/b45208bbd06e648668e2 to your computer and use it in GitHub Desktop.
Learning Swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Uses LLVM compiler just like Objective C. | |
//optional: variables that may not be used. contains null. | |
import UIKit | |
//variables | |
var str = "Hello, playground" | |
var myInteger = 90; //semicolon is optional | |
var boolExample = true //or false | |
println("The array is: \(myInteger)"); | |
//constants | |
let myConstant = 100; | |
//arrays | |
//heterogeneous arrays work as NSArrays. | |
//some of these methods didnt work in that. | |
var myArray = ["Red", "Blue"]; | |
println("The array is: \(myArray[0])"); | |
println("The array size is: \(myArray.count)"); | |
println("The array size is: \(myArray.last)"); | |
myArray.insert("Now at first", atIndex: 0); | |
//dictionary | |
var myDictionary = ["country": "India", "state": "Tamil Nadu", "city": "Chennai"]; | |
println(myDictionary["country"]) | |
//control statements | |
if(myInteger == 90){ | |
println("hello"); | |
} | |
for i in 0...1 | |
{ | |
println("\(i)"); | |
} | |
for element in myArray{ | |
println(element); | |
} | |
var myChar = "h" | |
switch(myChar) | |
{ | |
case "a", "e", "i", "o", "u": println("vowel"); break; | |
case "b": println("b"); break; | |
case "h": println("ee"); fallthrough; break; //break will never execute | |
//fallthrough also considers others case statements till next break; | |
case "d": println("d"); break; | |
case "e": println("e"); break; | |
default: println("haha"); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment