Created
January 7, 2016 14:04
-
-
Save Appletone/bf51e30717e30a816065 to your computer and use it in GitHub Desktop.
Create a new NSManagedObject with init method (Xcode 7.2 Swift 2.1 ) from: http://stackoverflow.com/a/33583941
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 { | |
// Returns the unqualified class name, i.e. the last component. | |
// Can be overridden in a subclass. | |
class func entityName() -> String { | |
return String(self) | |
} | |
convenience init(context: NSManagedObjectContext) { | |
let eName = self.dynamicType.entityName() | |
let entity = NSEntityDescription.entityForName(eName, inManagedObjectContext: context)! | |
self.init(entity: entity, insertIntoManagedObjectContext: context) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment