Beginning SwiftUI by Lim Greg
Author:Lim, Greg [Lim, Greg]
Language: eng
Format: epub
Published: 2021-03-18T16:00:00+00:00
do {
try viewContext.save()
} catch {
let error = error as NSError
fatalError("unresolved error:\(error)")
}
}
We loop through the indexes that ought to be deleted, retrieve the exact ManagedObject at that index and call the Managed Object Contextâ s delete() . After the for loop, we save the Core Data context.
Running your App
When you run your app now, upon swiping the cells to the left and hitting the red Delete button, the todos will be permanently deleted.
Updating in Core Data
We will go through the essential code to perform an update in Core Data. Letâ s allow the user to add a smiley face on to the todo name whenever she does a long press gesture on a todo, indicating that the todo is done.
Add a .onLongPressGesture modifier on the NavigationLink :
NavigationLink(destination:
â¦
}.onLongPressGesture(perform: {
updateTodo(todo: todo)
})
Create a function updateTodo with the following code:
private func updateTodo(todo: FetchedResults<TodoCD>.Element){
todo.name = " �� " //press control+commmand+space for emoticon editor
do {
try viewContext.save()
} catch {
let error = error as NSError
fatalError("unresolved error:\(error)")
}
}
As you can see, updating a Managed Object in Core Data involves just retrieving it, changing the value of its properties and then saving the context. You can extend this to updating the todoâ s name and category.
Running your App
When you run your app and do a long press on a todo , the name will change to a smiley face (fig. 5)! And all these data are kept persistent.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7763)
Filmora Efficient Editing by Alexander Zacharias(5770)
The Infinite Retina by Robert Scoble Irena Cronin(5246)
Learn Wireshark - Fundamentals of Wireshark. by Lisa Bock(3969)
Linux Device Driver Development Cookbook by Rodolfo Giometti(3933)
Edit Like a Pro with iMovie by Regit(3419)
Linux Administration Best Practices by Scott Alan Miller(2858)
Linux Command Line and Shell Scripting Techniques by Vedran Dakic & Jasmin Redzepagic(2835)
MCSA Windows Server 2016 Study Guide: Exam 70-740 by William Panek(2520)
Mastering PowerShell Scripting - Fourth Edition by Chris Dent(2393)
Docker on Windows by Stoneman Elton(2317)
Kali Linux - An Ethical Hacker's Cookbook: End-to-end penetration testing solutions by Sharma Himanshu(2313)
Creative Projects for Rust Programmers by Carlo Milanesi(2240)
Hands-On AWS Penetration Testing with Kali Linux by Karl Gilbert(2107)
Hands-On Linux for Architects by Denis Salamanca(2051)
Programming in C (4th Edition) (Developer's Library) by Stephen G. Kochan(2004)
Computers For Seniors For Dummies by Nancy C. Muir(1996)
The Old New Thing by Raymond Chen(1940)
Linux Kernel Debugging by Kaiwan N Billimoria(1762)
