当我使用propertiesToGroupBy时,我遇到了executeFetchRequest的问题。我需要获取日期(保存为字符串),但应避免使用相似的日期,以便获得唯一的日期数组。下面是我使用的代码
var arrDates: NSArray = NSArray()
let fetchRequestDates = NSFetchRequest(entityName: "Schedule")
fetchRequestDates.propertiesToGroupBy = ["date"]
fetchRequestDates.propertiesToFetch = ["date"]
fetchRequestDates.resultType = .DictionaryResultType
do {
let result = try managedContext.executeFetchRequest(fetchRequestDates)
arrDates = result as NSArray
} catch {
NSLog("Failed to fetch dates: \(error)")
}
执行没有进一步
let result = try managedContext.executeFetchRequest(fetchRequestDates)
并导致SIGBART。如果我评论
fetchRequestDates.propertiesToGroupBy = ["date"]
它可以工作,但也会获取重复的日期。工作是什么?