Ios Swift核心数据-使用N表达式和;NSFETCH请求
好的,我有一个名为“ScheduledEntry”的核心数据实体,它包含很少的属性。我的目标是通过总和在tableView中显示内容 获取的代码是:Ios Swift核心数据-使用N表达式和;NSFETCH请求,ios,swift,xcode,core-data,nsfetchrequest,Ios,Swift,Xcode,Core Data,Nsfetchrequest,好的,我有一个名为“ScheduledEntry”的核心数据实体,它包含很少的属性。我的目标是通过总和在tableView中显示内容 获取的代码是: func taskFetchRequest() -> NSFetchRequest { let fetchRequest = NSFetchRequest(entityName: "ScheduledEntry") let sortDescriptor = NSSortDescriptor(key: "name", ascen
func taskFetchRequest() -> NSFetchRequest {
let fetchRequest = NSFetchRequest(entityName: "ScheduledEntry")
let sortDescriptor = NSSortDescriptor(key: "name", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
return fetchRequest
我尝试(但没有成功)将此设置到taskFetchRequest函数:
fetchRequest.resultType = NSFetchRequestResultType()
var expressionDescription = NSExpressionDescription()
expressionDescription.expression = NSExpression(forKeyPath: "@sum.value")
expressionDescription.expressionResultType = NSAttributeType.DecimalAttributeType
fetchRequest.propertiesToFetch = [expressionDescription]
所以我的问题是——我做错了什么?什么是正确的解决方案?您有什么问题。Swift 2.2的语法似乎还可以。(一个警告是,
var expressionDescription
会更好,因为let
)问题是整个应用程序在应用程序委托上崩溃:)可能如果您显示崩溃时得到的堆栈跟踪,就更容易猜测。如果您想在属性中使用表达式描述,请,必须为提取指定resultType。DictionaryResultType
。NSFetchRequestResultType()默认为。ManagedObjectResultType
。您有什么问题。Swift 2.2的语法似乎还可以。(一个警告是,var expressionDescription
会更好,因为let
)问题是整个应用程序在应用程序委托上崩溃:)可能如果您显示崩溃时得到的堆栈跟踪,就更容易猜测。如果您想在属性中使用表达式描述,请,必须为提取指定resultType。DictionaryResultType
。NSFetchRequestResultType()默认为.ManagedObjectResultType
。