我已經從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」)'... –