I am new to Swift 2. Being learning extension, which I found it is pretty cool feature compared with OC.
An example from apple developer: https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/Extensions.html
extension Int {
mutating func square() {
self = self * self
}
}
var someInt = 3
someInt.square()
// someInt is now 9
So I was thinking, is it possible to have extension to return value like this:
extension Int {
func square() {
return self * self
}
}
var someInt = 3
someInt.square()
//ERROR: error: no '*' candidates produce the expected contextual result type '()'
My question is how to return a value within an extension? Thanks