I have a to-one relationship between a Document and Settings model:
On creation of a Document, a corresponding Settings object is created. The models are persisted to core data.
When relaunching after creating a few documents (and the associate settings), the application reloads a list of documents to select using:
// Load delegate from shared application and context from delegate.
SampleAppDelegate *delegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = delegate.managedObjectContext;
// Create new request.
NSFetchRequest *request = [[NSFetchRequest alloc] init];
// Create entity description using delegate object context.
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Document" inManagedObjectContext:context];
// Set entity for request.
[request setEntity:entity];
// Load array of documents.
NSError *error;
NSArray *documents = [context executeFetchRequest:request error:&error];
// Rlease descriptor.
[descriptor release];
// Release request.
[request release];
// Done.
return documents;
The list appears fine (the documents are loading). However, when attempting to access the settings for any of the documents the program exits giving:
Program received signal: “SIGABRT”.
The modifications to the settings are triggered when a user selects a button. Strangely enough, the program does not crash if the following snippet is added just before returning the documents on load (i.e. if the relationships are accessed while loading):
for (Document *document in documents)
{
NSLog(@"document.name: %@", document.name);
NSLog(@"document.settings.stroke: %@", document.settings.stroke);
NSLog(@"document.settings.stroke: %@", document.settings.stroke);
}
The property for the relationship is "(nonatomic, retain)" and uses "@dynamic". Any ideas? Thanks!