4
我想實現我自己的convenience init(context moc: NSManagedObjectContext)
版本,在iOS中10原因上NSManagedObject新的便利初始化器是我需要使它與iOS兼容9獲取類名的init斯威夫特3
我「已經想出了這一點:
convenience init(managedObjectContext moc: NSManagedObjectContext) {
let name = "\(self)".components(separatedBy: ".").first ?? ""
guard let entityDescription = NSEntityDescription.entity(forEntityName: name, in: moc) else {
fatalError("Unable to create entity description with \(name)")
}
self.init(entity: entityDescription, insertInto: moc)
}
,但它並沒有因爲這個錯誤的工作...
'self.init調用之前使用自我'
有誰知道如何解決這個錯誤,或以另一種方式實現相同的結果。
這是完美的。謝謝。 –