我在这里提到答案:https://stackoverflow.com/a/24061386/58129
代码转载于此:
var clazz: NSObject.Type = TestObject.self
var instance : NSObject = clazz()
if let testObject = instance as? TestObject {
println("yes!")
}
如果我在XCode6 beta6的操场上试过它,它会引发异常:
通过调用T.self()