ava ava - 2 months ago 20
iOS Question

Creating Model URL for Core Data

I want to using core data to save and load my data that I get from server:

private lazy var managedObjectModel : NSManagedObjectModel = {
let modelURL = NSBundle.mainBundle().URLForResource(self.manageObjectModelName, withExtension:"mom")!
return NSManagedObjectModel(contentsOfURL: modelURL)!
}()


I have an error


unexpectedly found nil


while unwrapping an Optional value in this code. And my
persistanceStoreCooardinator
storage and
mainQueueContext
storage are nil.
How can solve this problem?

Answer

Typo in this line mom instead of momd:

let modelURL = NSBundle.mainBundle().URLForResource(self.manageObjectModelName, withExtension:"momd")!