Unified Contacts

22 June, 2014

Array type of parameter in function

Two ways to pass an array into a function:

1. Passing in a sequence
func sumOf(numbers: Int...) -> Int {
    ...
}
sumOf(42, 597, 12)

2. Passing in a Array object
func sumOf(numbers: [Int]) -> Int {
    ...
}
let numbers = [42, 597, 12]
sumOf(numbers)

In the 1st example, array is passed as a sequence of Int. In the 2nd example, an object of Array is required, otherwise, there will be an error. You may see that no matter you use Int... or [Int], numbers is an array inside the function.


Learning Swift


Here are the links to download free Swift Programming Guide from iBooks Store.

- The Swift Programming Language
- Using Swift with Cocoa and Objective-C

18 June, 2014

Swift is the future

Apple announced Swift in WWDC 2014. Although you can combine Swift and Objective-C in one app. Swift is the future of Apple developer. Swift is more safe, more efficient, more easy to write and read.

In this blog, I will focus more in Swift, including how Swift works, how Swift combine Objective-C, etc. Stay Tuned :D