我已经从CoreData返回了一个Customer
对象。我试图计算存在于NSSet中所有amount
属性的总和:通过每个记录NSSet中属性的总和
extension Customer {
//...
@NSManaged var customer_Invoices: NSSet?
}
extension Invoice {
//...
@NSManaged var amount: NSDecimalNumber?
@NSManaged var invoice_Customer: Sale?
}
我能循环,并添加他们,但我认为有一个更好的办法?
这样做的最好方法是什么?在C#中,我通常只使用简单的linq
查询,在Swift中是否存在类似的东西?
查看[Key-Value coding collection operators](https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/CollectionOperators.htm)。就像'customer_Invoices.valueForKeyPath(“@ sum.amount”)'... –