NSPersistentDocument or data model names that are different then the bundle name.
Closed this issue · 1 comments
I have been working through an exception error that I was getting using NSPersistentDocument.
Basically what I found is that the xcdatamodel file was NOT the same name as the project name.
When I created a pure CoreData project the data model is the same as the project. But not when you do a "document" type project with core data. ACD assumes that the model name is the same as the Bundle name.
The edit I needed to make was to override the model name here. It appears to work (meaning it doesn't throw an exception anymore).
in DataContextOptions.swift:
`
private func managedObjectModelURLForManagedObjectModelName(managedObjectModelName: String) throws -> NSURL {
//guard let url = self.URLForResource(managedObjectModelName, withExtension: "momd") else {
guard let url = self.URLForResource("Document", withExtension: "momd") else {
throw AlecrimCoreDataError.InvalidManagedObjectModelURL
}
return url
}
`
I also tried changing the name of the data model file to the project name, but then acdgenp threw a vague error and I didn't have time to debug it. Going that route seemed more complex than just changing the code above.
Is there a better way for me to address this issue?
Thanks
bob
Hello. You can use the public init(managedObjectModelURL: NSURL, persistentStoreURL: NSURL)
initializer while creating the DataContextOptions
(as a parameter to the data context initializer). This way you can construct and specify the correct URLs. All other DataContextOptions
initializers are there for convenience, covering just the common cases.