我正在尝试从核心数据中获取不同行的数组,我正在尝试下面的代码。
func fetchDataFromLocalDB() {
if #available(iOS 10.0, *) {
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let managedContext = appDelegate.persistentContainer.viewContext
let request = NSFetchRequest<NSFetchRequestResult>(entityName: "Session_Subjects")
let predicate = NSPredicate(format: "dmode_id == %@", "\(User.deleveryMode)")
request.resultType = .dictionaryResultType
request.propertiesToFetch = ["subject_id"]
request.returnsDistinctResults = true
request.predicate = predicate
do{
// Here my app is crashing
arrResultSubject = try managedContext.fetch(request) as! [Session_Subjects]
}
catch {
// print(eror)
}
} else {
// Fallback on earlier versions
}
//For data fetch in coredata
let sectionIndex = IndexSet(integer: 0)
self.tableSubjectView.reloadSections(sectionIndex, with: .automatic)
}
但是当我在[Session_Subjects]上面分配值是coredata类的数组时,我会崩溃。
提前感谢。