1

如果我搜索一个Customer对象并且发现客户存在,那么我想将该对象分配给Customer一个invoice.customerInvoice对象的属性。我可以执行以下操作吗?

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 的所有属性Customerinvoice.customer。这样做时有什么注意事项吗?

4

0 回答 0