I'm trying to clear all rows from a table in Magical Record in Swift. I tried:
DeviceLog.mr_truncateAll()
but this seems to have no effect. Does someone know how to do it properly?
Thanks in advance.
Looks like I wasn't awake, it worked when I do it in save.
MagicalRecord.save({ (context) in
DeviceLog.mr_truncateAll(in: context)
}, completion: { (changed, error) in
if let _ = error {
print("Error truncating DeviceLog: \(String(describing: error?.localizedDescription))")
} else {
print("Truncate DeviceLog successful: \(changed)")
print(DeviceLog.mr_countOfEntities())
}
})
Or you could just use this
DeviceLog.mr_truncateAll(in: context)
context.mr_saveToPersistentStoreAndWait()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.