0
대 insertNewObject 사이에 어떤 차이 :코어 데이터 : 나는이 문제에 대한 두 가지 솔루션을 발견 지정 초기화
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