I have the following code.
ViewController.Swift
class ViewController: UIViewController {
override func viewDidLoad() {
let someClass = Test()
someClass.someProtocol.someMethod()
}
}
Code.Swift
protocol SomeProtocol {
var someInt: Int {get set}
func someMethod()
}
class SomeClass: SomeProtocol {
var someInt: Int
init() {
someInt = Int()
}
func someMethod() {
print("hello")
}
}
class Test {
let someProtocol: SomeProtocol
init() {
self.someProtocol = SomeClass()
}
}
This code compiles completely fine on Xcode 6/Swift 1.2, but in Xcode 7/Swift 2 someMethod
is never called, instead I get a EXC_BAD_ACCESS
on someInt
However if I move the code from Code.Swift to the ViewController.Swift file (so that all the source code is in the same file) I don't get a crash.
Has anyone experienced this issue with Swift 2 or know why this is happening? Thanks
Update : Even stranger, if I mark the SomeClass class as final, I don't get a EXC_BAD_ACCESS crash, but the method still never gets called.
it works as expected, at least for me. I checked it on both XCode 7.2.1 and last 7.3 beta resp.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.