Question : how to fetch core data
Answered by : rohan-patel-rqz0zer3zml0
// For this example, the name of my Core Data Entity is 'TaskItem'
// This can be placed in any SwiftUI View Struct to declare a variable array of your core data entries that automatically refreshes on changes to the core data model
@FetchRequest( sortDescriptors: [ NSSortDescriptor(keyPath: \TaskItem.dueTime, ascending: true), NSSortDescriptor(keyPath: \TaskItem.complete, ascending: true) ], predicate: NSCompoundPredicate(andPredicateWithSubpredicates: [NSPredicate(format: "%K >= %@", #keyPath(TaskItem.dueTime), todayDateFrom! as NSDate)]), animation: .default ) var tasks: FetchedResults<TaskItem>
Source : | Last Update : Wed, 17 Aug 22
Question : fetch request core data
Answered by : dark-dingo-x4zphs14rg4d
override func viewWillAppear(_ animated: Bool) { if let context = (UIApplication.shared.delegate as? AppDelegate)?.persistentContainer.viewContext { if let coreDataToDoItems = try? context.fetch(ToDoItem.fetchRequest()) as? [ToDoItem] { toDo = coreDataToDoItems } }
}
Source : | Last Update : Wed, 22 Apr 20
Question : fetch request core data
Answered by : itchy-ibex-hutq8prbwp7x
// entire usable func for fetching data func loadData() { if let context = (UIApplication.shared.delegate as? AppDelegate)?.persistentContainer.viewContext { if let hellos = try? context.fetch(Hello.fetchRequest()) as? [Hello] { } } }
Source : | Last Update : Wed, 22 Apr 20