I'm working on a simple app, and am looking to include some Core Data functionality from the Today Widget. It's giving me some trouble however, and I'm not sure what it is I'm missing.
Here's what I have done:
- I've added the widget target to the Core Data model
- I have NOT added my entity subclasses. This opens a can of worms with a bunch of sharedApplication references. I don't need to do much within the widget, so I think it will be much easier to just work with NSManagedObject instances.
In viewDidLoad of the widget I create a persistent container:
NSPersistentContainer *myContainer = [[NSPersistentContainer alloc] initWithName:@"MyDataModelName"]; [myContainer loadPersistentStoresWithCompletionHandler:^(NSPersistentStoreDescription *storeDescription, NSError *error) { if (error != nil) { NSLog(@"Unresolved error %@, %@", error, error.userInfo); abort(); } }];
So far so good, and no error is returned.
However, no results are returned when I call:
[myContainer.viewContext executeFetchRequest:request error:&error];
Entity Name and predicates don't seem to make a difference. No request error is returned. Identical requests work fine within the app proper.
It would seem that I am maybe initiating an empty container instead of grabbing the correct one? I'm sure this is a simple thing, but I'm at a loss. Any help is appreciated.