0
코어 데이터에서 페치 중입니다. 시간 특성으로 저장된 bool 특성이 있습니다. 부울이 사실 일 때 날짜 배열을 반환해야합니다. 나는 그것이 작동하도록 할 수 없다, 나는 빈 날짜의 배열을 얻는다, 또는 그것은 부서진다.여러 개의 sortDescriptors 및 Bool 필터가있는 Swift fetchRequest
func datesWithCompleteHBI() -> [Date] {
let managedObjectContext = (UIApplication.shared.delegate as! AppDelegate).managedObjectContext
fetchRequest.resultType = .dictionaryResultType
fetchRequest.propertiesToFetch = ["savedTime", "harveyBradshawIndexComplete"]
let timeSort = NSSortDescriptor(key: "savedTime", ascending: false)
let hbiSort = NSSortDescriptor(key: "harveyBradshawIndexComplete", ascending: false)
fetchRequest.sortDescriptors = [timeSort, hbiSort]
let messageKey = true
fetchRequest.predicate = NSPredicate(format: "harveyBradshawIndexSaveLevel = %@", messageKey as CVarArg)
var dates = [Date]()
do {
let results = try managedObjectContext.fetch(fetchRequest) as! [[String:Date]]
dates = results.flatMap { $0["savedTime"]}
} catch let error as NSError {
print("Could not fetch \(error), \(error.userInfo)")
}
print("hbi date array \(dates)")
return dates
}
}
오류가 발생했습니다. '('[String : Any]) throws -> Bool) '인수 목록과 함께'필터 '를 호출 할 수 없습니다.' – SashaZ
답변을 업데이트했습니다. 술어에서 오브젝트를 필터링하는 것이 더 나은 해결책입니다. – vadian
죄송합니다. 도와 줘서 고마워. 내가 알아낼 때 대답을 게시 할 것이다. – SashaZ