我对 Swift 2.2 (Xcode 7.3) 感到沮丧。要模拟它,只需在用户定义的通用类中创建一个变量,然后从其他地方引用该类。例如:
class A<T> {
let genVar = 1
}
class MyViewController: UIViewController {
let myVar = A<Int>() // crash is here
}
如果您将在运行 iOS 7 的设备(在我的情况下为 iPhone 4)上运行此代码,它会在尝试创建泛型类型的变量时崩溃。以下是设备崩溃日志的第一行:
Exception Type: EXC_BAD_ACCESS (SIGBUS)
Exception Subtype: KERN_PROTECTION_FAILURE at 0x00298910
Triggered by Thread: 0
Thread 0 Crashed:
0 libswiftCore.dylib 0x006b1d64 0x4bd000 + 2051428
1 Phone 0x001c76ec 0xab000 + 1165036
2 libswiftCore.dylib 0x006b307c 0x4bd000 + 2056316
3 libswiftCore.dylib 0x006b2f70 0x4bd000 + 2056048
4 libswiftCore.dylib 0x006b0f24 0x4bd000 + 2047780
5 libswiftCore.dylib 0x006b107c 0x4bd000 + 2048124
6 Phone 0x0014e730 0xab000 + 669488
7 Phone 0x00129390 0xab000 + 517008
8 UIKit 0x31e9d9c4 -[UIClassSwapper initWithCoder:] + 188
在 iOS 8 和 9 模拟器/设备上,上面的代码可以正常工作。
Swift 对 iOS 7 的支持会在不久的将来放弃吗?