Skip to content

Instantly share code, notes, and snippets.

@tempire
Created May 24, 2015 03:00
Show Gist options
  • Select an option

  • Save tempire/9636ae4c8d912b014f00 to your computer and use it in GitHub Desktop.

Select an option

Save tempire/9636ae4c8d912b014f00 to your computer and use it in GitHub Desktop.
extension NSManagedObject {
class func createEntity<T: NSManagedObject>(context: NSManagedObjectContext) -> T {
return NSEntityDescription.insertNewObjectForEntityForName(NSStringFromClass(T), inManagedObjectContext: context) as! T
}
}
class Customer: NSManagedObject {
@NSManaged var id: NSNumber
}
Then call it:
let customer = Customer.createEntity(managedObjectContext)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment