14 July, 2014
Half-Open Range Operator changed in Xcode 6.0 Beta 3
You may see in the Swift programming guide, half-open range operator is written as 0..9 (the range is from 0 to 8, not including 9). In beta 3, it is changed to 0..<9 (much more meaningful, but personally feel it is not beautiful). A less than symbol is added.
05 July, 2014
The difference of let array and let dictionary
In Swift, let is used to declare constant and var is used to declare variable. In Objective-C, there are array and mutable array, also dictionary and mutable dictionary. Instinctively, you may think constant array is not mutable and the values inside the array is not editable. The truth is a constant array is not mutable but you may edit the values inside. However, constant dictionary is not the same as array. A constant dictionary is not mutable or editable.
I don't know why constant array is that special :(
Update:
Start from Beta 3, let array is now completely immutable, and var array is completely mutable.
Link: Swift Language Changes in Xcode 6 beta 3
I don't know why constant array is that special :(
Update:
Start from Beta 3, let array is now completely immutable, and var array is completely mutable.
Link: Swift Language Changes in Xcode 6 beta 3
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.
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
In this blog, I will focus more in Swift, including how Swift works, how Swift combine Objective-C, etc. Stay Tuned :D
14 May, 2014
AdMob SDK 6.9.2
Google has just released AdMob SDK 6.9.2. In this version google utilized IDFA API. When you submit app with AdMob SDK 6.9.2, you have to tell apple you are using IDFA in your app, otherwise, your binary will be rejected.
14 April, 2014
How to check where is the exception thrown
Sometimes when the exception thrown. Xcode just shows the memory status, but not exactly the line of code. If you want to see where is the exception thrown. You can add a exception breakpoint.
1. click the breakpoint tap on the left side navigators window.
2. on the left bottom, click the + button and then click "Add Exception Breakpoint".
3. now, when exception is thrown, Xcode will show which code has a problem.
1. click the breakpoint tap on the left side navigators window.
2. on the left bottom, click the + button and then click "Add Exception Breakpoint".
3. now, when exception is thrown, Xcode will show which code has a problem.
Subscribe to:
Posts (Atom)




