Confused in getting the ManagedObjectContext from AppDelegate

大城市里の小女人 提交于 2019-12-05 06:42:45
Brad Larson

There is significant discussion about where people favor placing the Core Data stack in this question. I tend to place the stack within a singleton (as I indicate there). This gives you convenient access to the stack wherever you need it within your application.

As far as your problem, I find it highly unlikely that the elements of your Core Data stack have been deallocated. For one thing, you'd be crashing on sending a message to your context or model, rather than getting back the report you are now. If you can access the "Song" entity from somewhere else in your application, my bet is that you're not passing the model ot context properly to the instance that needs it.

IIRC the Apple examples initialize the Core Data stack in the App Delegate but they actually setup properties on the view controller to reference the ManagedObjectContext and set those on application load - what Apple's docs is referring to as I read it is that you should do something similar rather than trying to load the ManagedObjectContext directly from the App Delegate.

If you post some code it will be a lot easier to help you figure out what is going on with your error. The first thing I'd check is that the reference to the ManagedObjectContext in your controller is not nil.

THe problem you have here is because you have not declared an entity named songs in your object model...The pattern you are following has nothing to do with it...I suggest you read up on core data and the object model here. Hope that helps you

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!