简体   繁体   中英

iPhone Core Data Missing Entities

I've had an app that I've been working on for a while that I originally included Core Data support in, but didn't actually start trying to use it until recently. Now that I'm actually trying to use Core Data ... it doesn't seem like I can. When I edit my xcdatamodel to include new (or really, any) entities, I can't seem to actually access those entities in the application itself. Somewhere along the way, I renamed the project from ProjectTest to CoreDataTest, which I suspect is causing or is related to this problem. I haven't changed any of the default methods which were generated in the app delegate initially by Xcode (initially 3, but now using 4).

So, I've created a new entity called simply enough TestEntity with a single attribute (String) TestAttribute.

In my app delegate, I've tried a couple of different ways to access the Entity and save a string to it, but all fail. So I thought I'd walk through all entities thinking I was somehow messing up creating the creation of the NSEntityDescription. I put the following code in to show a listing of all Entities ... and got nothing:

NSManagedObjectModel *model = [[self.managedObjectContext persistentStoreCoordinator]
                               managedObjectModel];
NSLog(@"List of Entities:");
for (NSEntityDescription *entity in model)
{
  NSLog(@"Entity: %@", entity);
}
NSLog(@"Done with list");

For an output I just get:

2011-09-21 14:58:01.955 CoreDataTest[1813:b603] List of Entities:
2011-09-21 14:58:01.955 CoreDataTest[1813:b603] Done with list

So ... I've tried cleaning the build. I've searched through a lot of questions here on SO and more on google, but I can't seem to find anything that solves my problem. I don't get any actual error messages or uncaught exceptions during a run of the app. Any ideas what could be causing it? I'm sure it's probably something stupidly simple that I'm overlooking ...

Thanks for any help,

Will

Try adding .entities, ie:

for (NSEntityDescription *entity in model.entities) { //...

See The docs for NSManagedObjectModel .

Also check your model is not null. Try printing it: NSLog(@"%@",model);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM