Created
March 10, 2015 09:32
-
-
Save ankahathara/191a9fc1a105d23d5650 to your computer and use it in GitHub Desktop.
Swift Basics 1
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
// Playground - noun: a place where people can play | |
import Foundation | |
var greetings = "Hello" | |
greetings = greetings + "World" | |
greetings.append(Character("!")) | |
println(greetings) | |
// Swift string is a value type, as a result when you assign a string to a variable, a constant, or pass it as an argument to a function, its value is copied. | |
// In swift you can use Objective C methods by importing appropriate Header files; for example if you import Foundation then you can use the NSString functions with the swift string type | |
// let keyword is a constant type in swift while the var keyword is the variable type means you can change the value of the variable | |
// Swift does not need the semicolon | |
// Compiler can determine the size of the byte if the app runs on the 32 bit it will consider it as a 32 byte and if it runs on the 64 bit it will consider it as a 64 byte. | |
// You can use the underscore as a thousands separator. let million = 1_000_000 | |
// You cannot to arithmatic operation with different type variables. all the variables should have the same type and cannot be implicitly converted as it can be in the Objective C | |
// Tuples can be access via their indices | |
// String interpolation means that you can embed values when you use println() method using \(). | |
// for loops : | |
//var i in 1...5 | |
//var i in 1..<6 | |
//for i in "Swift" { | |
// println("\(i)") | |
//} | |
// switch | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment