Using dynamicType total result in EXC_BAD_ACCESS
The following code works fine in iOS Simulator, but throws an EXC_BAD_ACCESS exception on the device.
Is this a bug in Swift or am I just doing something weird here?
What does not work:
class Foo: NSObject {
class var name: String {
return "A foo"
}
}
struct FooWrapper<T: Foo> {
var fooName: String
init(foo: T) {
fooName = foo.dynamicType.name
}
}
var foo = Foo()
var fooWrapper = FooWrapper(foo: foo)
println(fooWrapper.fooName)
To make it work:
- Use
(foo as Foo).dynamicType.name
- Or remove NSObject as superclass Foo
+3
source to share
No one has answered this question yet
See similar questions:
or similar: