如果我搜索一个Customer
对象并且发现客户存在,那么我想将该对象分配给Customer
一个invoice.customer
新Invoice
对象的属性。我可以执行以下操作吗?
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:[NSEntityDescription entityForName:@"Customer" inManagedObjectContext:self.objectContext]];
request.returnsObjectsAsFaults=NO; //populate beverage object
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(id == %@)", customerID];
[request setPredicate:predicate];
NSError *error = nil;
NSArray *array = [self.objectContext executeFetchRequest:request error:&error];
if([array count] == 1)
{
invoice.customer = (Customer*)[array objectAtIndex:0];
}
我要避免的是必须重新分配 to 的所有属性Customer
值invoice.customer
。这样做时有什么注意事项吗?