Swift Tutorial - Tutorialspoint
import Cocoa var intsA = [Int](count: 2 , repeatedValue: 2 ) var intsB = [Int](count: 3 , repeatedValue: 1 ) var intsC = [Int]() ...
Swift dictionaries are used to store unordered lists of values of the same type. Swift puts strict checking which does not allow ...
Let's check the following example to create, initialize, and access values from a dictionary: import Cocoa var someDict:[Int:Str ...
Old value of key = 1 is Optional("One") Value of key = 1 is Optional("New value of one") Value of key = 2 is Optional("Two") Val ...
println( "Value of key = 1 is \(someDict[1])" ) println( "Value of key = 2 is \(someDict[2])" ) println( "Value of key = 3 is \( ...
println("Dictionary key \(key) - Dictionary value \(value)") } When the above code is compiled and executed, it produces the fol ...
for (key) in dictKeys { println("\(key)") } println("Print Dictionary Values") for (value) in dictValues { println("\(value)") } ...
The empty Property You can use read-only empty property of a dictionary to find out whether a dictionary is empty or not, as sho ...
A function is a set of statements organized together to perform a specific task. A Swift function can be as simple as a simple C ...
} println(student("First Program")) println(student("About Functions")) When we run the above program using playground, we get t ...
} println(mult( 2 , 20 )) println(mult( 3 , 15 )) println(mult( 4 , 30 )) When we run above program using playground, we get the ...
func ls(array: [Int]) - > (large: Int, small: Int) { var lar = array[ 0 ] var sma = array[ 0 ] for i in array[1..<array.co ...
Functions with Optional Return Types Swift introduces 'optional' feature to get rid of problems by introducing a safety measure. ...
Here, the func sample argument number is declared as internal variable since it is accessed internally by the function sample(). ...
func vari<N>(members: N...){ for i in members { println(i) } } vari( 4 , 3 , 5 ) vari(4.5, 3.1, 5.6) vari("Swift", "Enumer ...
a1 = b1 b1 = t } var no = 2 var co = 10 temp(&no, &co) println("Swapped values are \(no), \(co)") When we run the above ...
return name } Here the function is declared as string datatype. Functions may also have void data types and such functions won't ...
func sum(a: Int, b: Int) - > Int { return a + b } var addition: (Int, Int) - > Int = sum println("Result: \(addition(40, 8 ...
Closures in Swift are similar to that of self-contained functions organized as blocks and called anywhere like C and Objective C ...
Statement 2 --- Statement n } Following is a simple example: let divide = {(val1: Int, val2: Int) - > Int in return val1 / va ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf