let fetchRequest = NSFetchRequest(entityName: "Product")
fetchRequest.predicate = NSPredicate(format: "shopItem.wishList == %@", currentWishList)
fetchRequest.resultType = .DictionaryResultType
fetchRequest.sortDescriptors = [NSSortDescriptor(key: "mainBestPrice", ascending: true)]
let minPriceExpression = NSExpression(format: "min:(mainBestPrice)")
let minPriceED = NSExpressionDescription()
minPriceED.expression = minPriceExpression
minPriceED.name = "productPrice"
minPriceED.expressionResultType = .DoubleAttributeType
fetchRequest.propertiesToFetch = ["shopItem.keyword", "productTitle", minPriceED]
fetchRequest.propertiesToGroupBy = ["shopItem.keyword"]
我想組由一個場NSFetchRequest
,但總是出現錯誤:斯威夫特NSFetchRequest組由一個屬性
CoreData: error: Serious application error. Exception was caught during Core Data change processing. This is usually a bug within an observer of NSManagedObjectContextObjectsDidChangeNotification. SELECT clauses in queries with GROUP BY components can only contain properties named in the GROUP BY or aggregate functions
,我應該在組使用的所有字段propertiesToFetch
。但我不想這樣做...
沒辦法。您必須將'productTitle'添加到'propertiesToGroupBy',或將其從'propertiesToFetch'中移除。它可能是你可以得到你想要的不同方式:使用Key值編碼集合運算符或NSFetchedResultsController。如果你編輯你的文章以包含實體和關係的細節(一對多,多對多),我相信你會得到一些建議。 – pbasdf
我真的需要所有的領域,你可以告訴我怎麼可以在'''fetchRequest'''之後對結果進行分組? – Arti