0
対insertNewObject間のどのような違い私は問題には2つの解決策を発見した::指定イニシャライザ
public class MyClass: NSManagedObject {
init(_ entity:NSEntityDescription, dict: NSDictionary, context: NSManagedObjectContext) {
super.init(entity: entity , insertInto: context)
}
}
let entity = NSEntityDescription.entity(forEntityName: "MyClass", in: self.context!)
_ = MyClass.init(entity!, dict: item as! NSDictionary, context: self.context!)
と
let myClass = NSEntityDescription.insertNewObject(forEntityName: "MyClass", into: context) as! MyClass
を、私は最後の違いを理解することはできません。そしてそれはどのようにしてNSManagedObjectContext
に影響しますか?
私は最初のバージョンは認識していませんでしたが、私はあなたのために3番目を持っています:私はエンティティ名を知る必要性を避けることを好む 'let createe = MyClass(context:context)'を持っています。 – shallowThought