1

I am creating a Reddit client for iOS for learning purposes. I am using CoreData, which I set up by following the CoreData Basics NSScreencast and I used Mogenerator to generate the model files.

I added a breakpoint to catch all exceptions and when I call the insertInManagedObjectContext: class method provided by Mogenerator, the app crashes on the following line:

return [NSEntityDescription insertNewObjectForEntityForName:@"AZRedditAccount" inManagedObjectContext:moc_];

This line is in the model that Mogenerator generated (_AZRedditAccount). When I look at the Variables View, I noticed an odd line which I don't really understand...

Odd line in the Variables View

What do I need to do to make things work please?

Edit: Here is what I have in my .xcdatamodeld file:

My .xcdatamodeld file

Edit 2: I added the whole project to Github, thought it might help solve the problem: https://github.com/AzizLight/Reddit

4

1 回答 1

3

如果您调试,您会看到您的 ManagedObjectContext (MOC) 没有分配 PersistentStoreCoordinator (PSC),因此没有模型。在 AZRedditDataModel.m 中,您正在初始化 PSC,但您没有保留它(第 84-109 行)。如果没有模型,则上下文无法创建任何实体,因为没有“蓝图”。

于 2013-06-20T08:25:53.253 回答