在下面的例子中,T指的是擴展NSManagedObject的類型,爲什麼我不能調用。Swift - 從MetaType獲取類名?
我沒有訪問類的實例
private func getNewManagedObject <T: NSManagedObject>(type: T.Type) -> T {
// Let's assume all Entity Names are the same as Class names
let className = "" /*Somehow get class name from type ("User")*/
return NSEntityDescription.insertNewObjectForEntityForName(className, inManagedObjectContext: managedObjectContext) as T
}
getNewManagedObject(User.self);
斯威夫特3解決方案 'let className = String(describe:Int.self)// String' – 2016-11-27 02:59:51