People と Network の 2 つのエンティティがあります (xcdatamodeld 画面 - http://rghost.ru/47818182/image.png )。メソッドfetchで配列 people を抽出し、 network.urlを出力したいと思います。
エラー:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[_NSFaultingMutableSet url]: unrecognized selecto
コード:
- (IBAction)insert:(id)sender
{
NSMutableSet* networks = [NSMutableSet set];
// People entity
People *people = (People *)[NSEntityDescription insertNewObjectForEntityForName:@"People" inManagedObjectContext:self.managedObjectContext];
people.name = @"Alex";
people.age = @23;
// Network entity
Network *network = (Network *)[NSEntityDescription insertNewObjectForEntityForName:@"Network" inManagedObjectContext:self.managedObjectContext];
network.url = @"http://facebook.com/alex";
[networks addObject:network];
[people addNetwork:networks];
// Save
[self.managedObjectContext save:nil];
}
- (IBAction)fetch:(id)sender
{
NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"People"];
NSArray *peoples = [self.managedObjectContext executeFetchRequest:fetchRequest error:nil];
for (People *people in peoples)
{
Network *network = (Network *)people.network;
NSLog(@"%@", network.url);
}
}