YaroslavZhurbilo
9/4/2017 - 11:49 AM

From https://stackoverflow.com/questions/31358692/instantiate-a-nsmanagedobject-without-saving-it

@objc(User)
class User: NSManagedObject {

    @NSManaged var id: String

    //MARK: - Initialize
    convenience init(id: String, needSave: Bool,  context: NSManagedObjectContext?) {

        // Create the NSEntityDescription
        let entity = NSEntityDescription.entityForName("User", inManagedObjectContext: context!)


        if(!needSave) {
            self.init(entity: entity!, insertIntoManagedObjectContext: nil)
        } else {
            self.init(entity: entity!, insertIntoManagedObjectContext: context)
        }

        // Init class variables
        self.id = id

    }
}