如何批量为获取结果控制器返回的对象的属性赋值?

发布于 2024-12-11 20:00:23 字数 647 浏览 0 评论 0原文

好吧,我的数据库中存在一堆对象,它们的所有字段都已完成,除了两个......因为在创建对象时无法确定值。

现在我想在付款接收方法中插入代码,该代码会将相同的值(例如 $120.50)写入 fetchedResultsController 返回的所有对象的空白字段。

这就是我之前创建新对象并设置属性值时所做的操作。

newInvoice = [NSEntityDescription insertNewObjectForEntityForName:@"Invoice" inManagedObjectContext:managedObjectContext];


[newInvoice setValue:productTextField.text forKey:@"itemCode"]; 

对于 SQL 数据库中当前为空白的以下属性,我应该使用什么代码来设置所有返回对象的值?

[newInvoice setValue:amountPaidLabel.text forKey:@"amountPaid"];
[newInvoice setValue:paymentMethod.text forKey:@"PaymentMethod"];

我希望这是有道理的,任何意见都会受到赞赏

Ok so I have a bunch of objects that exist in my database, they have all fields completed except for two... as the value could not be determined at the time that the objects were created.

Now I want to insert code in a payment received method that will write the SAME value (eg. $120.50) to the blank fields for ALL objects returned by the fetchedResultsController.

This is what I had previously done to create a NEW object and set the values for the properties.

newInvoice = [NSEntityDescription insertNewObjectForEntityForName:@"Invoice" inManagedObjectContext:managedObjectContext];


[newInvoice setValue:productTextField.text forKey:@"itemCode"]; 

What code do I use to set the value of ALL returned objects, for the properties below which are currently blank in the SQL database?

[newInvoice setValue:amountPaidLabel.text forKey:@"amountPaid"];
[newInvoice setValue:paymentMethod.text forKey:@"PaymentMethod"];

I hope that made sense, any input would be kindly appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2024-12-18 20:00:23

我会在您的发票类上添加一个方法......

- (void)updateEmptyPaid:(NSNumber *)aValue {
  [self setValue:aValue forKey:@"amountPaid"];
}

对付款方式执行相同的操作,然后您可以执行...

[myInvoices makeObjectsPerformSelector:@selector(updateEmptyPaid:) withObject:newValue];
[myInvoices makeObjectsPerformSelector:@selector(updatePaymentMethod:) withObject:newValue];

其中 myInvoices 是 NSFetchRequest 结果的数组。

I would add a method on your invoice class...

- (void)updateEmptyPaid:(NSNumber *)aValue {
  [self setValue:aValue forKey:@"amountPaid"];
}

... do the same for the payment method and then you can do....

[myInvoices makeObjectsPerformSelector:@selector(updateEmptyPaid:) withObject:newValue];
[myInvoices makeObjectsPerformSelector:@selector(updatePaymentMethod:) withObject:newValue];

Where myInvoices is an array of the results from NSFetchRequest.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文