-1
私はSwift 2の新機能です。OCと比較して非常にクールな機能であることが分かったので、拡張機能を学習しています。アップルの開発者から拡張メソッドSwiftの戻り値
extension Int {
mutating func square() {
self = self * self
}
}
var someInt = 3
someInt.square()
// someInt is now 9
だから私は考えていたが、それは次のように値を返すように拡張子を持つことが可能です:
extension Int {
func square() {
return self * self
}
}
var someInt = 3
someInt.square()
//ERROR: error: no '*' candidates produce the expected contextual result type '()'
私の質問は、値を返す方法です拡張の中で? ありがとう
http://stackoverflow.com/a/26836477/2303865 –