在Swift 3中使用时NSFetchRequest,必须指定NSFetchRequestResult。但是如何获取属性值数组?如果我使用这样的东西
NSFetchRequest
NSFetchRequestResult
let fetchRequest = NSFetchRequest<MyClass>(entityName: "MyClass") fetchRequest.propertiesToFetch = ["myAttributeName"]
当我尝试执行获取请求时会触发异常。 error: -executeRequest: encountered exception = The database appears corrupt. 如果我删除一行,propertiesToFetch则不会有任何错误,但是会得到一组对象,而不是属性。
error: -executeRequest: encountered exception = The database appears corrupt.
propertiesToFetch
我忘了resultType为NSFetchRequest 设置。
resultType
let fetchRequest = NSFetchRequest<MyClass>(entityName: "MyClass") fetchRequest.propertiesToFetch = ["myAttributeName"] fetchRequest.resultType = .dictionaryResultType