I am storing persistent data in my application using NSCoder like below:
class UserNotification: NSObject, NSCoding {
var message: String!
init(message: String) {
self.message = message
}
required convenience init(coder aDecoder: NSCoder) {
let message = aDecoder.decodeObject(forKey: "message") as! String
self.init(message: message)
}
func encode(with aCoder: NSCoder) {
aCoder.encode(message, forKey: "message")
}
}
This is how they are loaded into the application:
let defaults = UserDefaults.standard
if (defaults.object(forKey: "userNotifications") != nil) {
let decoded = defaults.object(forKey: "userNotifications") as! Data
let decodedUserNotifications = NSKeyedUnarchiver.unarchiveObject(with: decoded as Data) as! [UserNotification]
userNotifications = decodedUserNotifications
}
I also have included a way for the user to clear all the saved data. For clearing, I have implemented:
let newListData = NSKeyedArchiver.archivedData(withRootObject: userNotifications)
let defaults = UserDefaults.standard
defaults.set(newListData, forKey: "userNotifications")
defaults.synchronize()
All user notification objects are stored in a globally accessible array:
userNotifications = [UserNotification]()
I would like to make sure that all the persistent data is removed once the user has cleared them. I was looking through the folder of my simulator (~/Library/Developer/CoreSimulator/Devices) in order to find the persistent data and to see if it gets removed, but I have not managed to find it anywhere.
Everything seems to work when running the application (saving data, erasing it etc.) but I would like to make sure that all data get erased correctly on the device. There are some thumbnails being saved and therefore I want to make sure it really becomes erased and not taking up unnecessary space.
So my question is where the data is stored when using NSCoder? I am able to find locally stored images from using FileManager, but the encoded data is nowhere to be found.