【发布时间】:2015-06-24 07:25:25
【问题描述】:
我有以下代码崩溃。
class PersonFactory {
class var build: PersonInterface {
get {
return Person()
}
}
}
class Person: PersonInterface {
var age: Int = 0
func say(message: String) {
print(message)
}
}
protocol PersonInterface: class {
var age: Int { get set }
func say(message: String)
}
当我从view controller 运行以下行时,它崩溃了:
PersonFactory.build.say("hello")
在以下行var age: Int = 0 上使用EXC_BAD_ACCESS 崩溃。该问题出现在 Xcode 7 beta 4 (7A165t) 中。
请注意,代码不会在 Playground 中崩溃,只有在从应用程序调用它时。这是演示应用程序:https://github.com/exchangegroup/ProtocolCrashDemo
注意:定义 PersonFactory、Person 和 PersonInterface 的代码应该放在一个单独的文件中,以免崩溃。
看起来像 Swift 2.0 的错误?我向 Apple 提交了错误报告。
更新
该问题已在 Xcode 7.0 beta 5 中修复。
【问题讨论】:
-
尝试将代码放在与视图控制器相同的源文件中。