objective c core data get all code example
Example 1: fetch request core data
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
}
}
}
Example 2: fetch request core data
func loadData() {
if let context = (UIApplication.shared.delegate as? AppDelegate)?.persistentContainer.viewContext {
if let hellos = try? context.fetch(Hello.fetchRequest()) as? [Hello] {
}
}
}