Skip to content

Instantly share code, notes, and snippets.

@tralamazza
Created February 21, 2017 12:03
Show Gist options
  • Save tralamazza/a16282b1ac73525f0399afabedfab37b to your computer and use it in GitHub Desktop.
Save tralamazza/a16282b1ac73525f0399afabedfab37b to your computer and use it in GitHub Desktop.
import CoreData
extension NSManagedObject {
convenience public init(insertInto context: NSManagedObjectContext?) {
let name = String(describing: type(of: self))
let entity = NSEntityDescription.entity(forEntityName: name, in: context!)
self.init(entity: entity!, insertInto: context)
}
}
@tralamazza
Copy link
Author

to create a managed object you simply do:

let sensor = Sensor(moc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment