【发布时间】:2015-08-16 19:53:39
【问题描述】:
目前我正在开发使用 Swift 2.0 编写的新应用程序。今天我在Xcode beta 5 中遇到了两个奇怪的错误。如果有以前测试版 Xcode 的人可以确认我是否正确,我会很高兴。我也可能会误解一些东西,所以我会很感激任何反馈。
以下是一些让我苦苦挣扎的示例代码:
// Frist bug
protocol SomeProtocol {
var someArray: [String] { get set } // #1 bug
}
extension SomeProtocol {
func someFunction(someString: String) {
self.someArray.append(someString) // #1: Immutable value of type '[String]' only has mutating members named 'append'
}
}
// Second bug
protocol SomeInterfaceProtocol {
var someBool: Bool { get set } // #2 bug
}
class SomeClass: SomeInterfaceProtocol {
var someBool: Bool = false
func returnInterface() -> SomeInterfaceProtocol {
return self
}
}
let someInstance = SomeClass()
// can't set the value
someInstance.returnInterface().someBool = true // #2: Cannot assign to property: function call returns immutable value
【问题讨论】: