Created
October 3, 2016 18:50
-
-
Save rbsgn/d02aa6d1039befd3f6d747cdd0a7e7f8 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
import CoreData | |
func newManagedObjectModel() -> NSManagedObjectModel { | |
// you get new instance of MOM with the same properties | |
// each time you call the function. | |
// this function uses entity description returned by | |
// newEntityDescription function | |
} | |
func newEntityDescription() -> NSEntityDescription { | |
// again, you get new instance of entity description | |
// with same properties each time you call the function | |
} | |
final class ManagedFoo: NSManagedObject { | |
@NSManaged var bar: String | |
} | |
func test_SavingWithManagedObjectContext() { | |
let coordinator = NSPersistentStoreCoordinator(managedObjectModel: newManagedObjectModel()) | |
let context = NSManagedObjectContext(concurrencyType: .PrivateQueueConcurrencyType) | |
context.persistentStoreCoordinator = coordinator | |
let foo = ManagedFoo(entity: newEntityDescription(), insertIntoManagedObjectContext: nil) | |
context.insert(foo) | |
try! context.save() // code will crash here with pretty obscure error 134020 “Store cannot hold instances of entity” | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One solution: