Created
May 24, 2015 03:00
-
-
Save tempire/9636ae4c8d912b014f00 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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