I just switch to Swift for couple days and I notice that the postfix and prefix ++ and -- will be removed in Swift 3. I have done some research and according to the announcement on the Swift website, the operator ++ and -- will be replaced by += 1 and -= 1. Link here New Features in Swift 2.2
I have a piece of code that work just fine with the old version of Swift. When I change from return counter1++
which is my original code to return counter1 += 1
and an error pops up saying
No '+=' candidates produce the expected contextual type 'Int'
Here is my example
func countingCounter() -> (() -> Int){
var counter1 = 0
let incrementCounter1: () -> Int = {
return counter1+=1 //original is counter1++
}
return incrementCounter1
}
I have tried to work this out but still stuck.