Skip to content

Instantly share code, notes, and snippets.

@thepost
Created December 4, 2018 03:52
Show Gist options
  • Save thepost/cea3ab0e0e834b68877d113cef5463d7 to your computer and use it in GitHub Desktop.
Save thepost/cea3ab0e0e834b68877d113cef5463d7 to your computer and use it in GitHub Desktop.
extension ModelController {
func add<M: NSManagedObject>(_ type: M.Type) -> M? {
var modelObject: M?
if let entity = NSEntityDescription.entity(forEntityName: M.description(), in: context) {
modelObject = M(entity: entity, insertInto: context)
}
return modelObject
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment