I have look around for something similar with no luck so I am going to try and explain my trouble and paste some code. I have an application that uses Core Data and I can save and retrieve data from their respective textFields with the exception of my (to many relationships). I believe these are saved and returned as sets when fetched. I have read up on NSSet and looked at some code but with still do not understand how to code it.
Thanks for any help. Hudson
- (IBAction) findContact
{
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Place"
inManagedObjectContext:context];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc]init];
[fetchRequest setEntity:entity];
NSPredicate *pred = [NSPredicate predicateWithFormat:@"placeName = %@", placeName.text];
[fetchRequest setPredicate:pred];
Place *matches = nil;
NSError *error;
NSArray *objects = [context executeFetchRequest:fetchRequest error:&error];
if ([objects count] == 0) {
status.text = @"No matches";
}else{
matches = [objects objectAtIndex:0];
address.text = [matches valueForKey:@"address"];
city.text = [matches valueForKey:@"city"];
state.text = [matches valueForKey:@"state"];
zip.text = [matches valueForKey:@"zip"];
phone1.text = [matches valueForKey:@"phone1"];
email.text = [matches valueForKey:@"email"];
website.text = [matches valueForKey:@"website"];
phone2.text = [matches valueForKey:@"phone2"];
about.text = [matches valueForKey:@"about"];
photoName.text = [[matches photo]valueForKey:@"photoName"];
status.text = [NSString stringWithFormat:@"%d matches found", [objects count]];
NSSet *groupForSections = [groupForSections valueForKey:@"sections"];
for (Group *group in groupForSections) {
NSLog(@"group name = %@", [groupForSections valueForKey:@"groupName"]);
groupName.text = [group valueForKey:@"groupName"];
NSSet *sectionForPlaces = [sectionForPlaces valueForKey:@"places"];
for (Section *section in sectionForPlaces) {
sectionName.text = [section valueForKey:@"sectionName"];
NSLog(@"section name = %@", [section valueForKey:@"sectionName"]);
}
}
}
}
![enter image description here][1]