我有两个实体:人员和网络(xcdatamodeld 屏幕 - http://rghost.ru/47818182/image.png)。在方法fetch我提取数组 peoples 并且我想打印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);
}
}