0
我使用NSKeyedArchive保存數據,並使用NSKeyedArchiver進行提取。導出/導入NSKeyedArchiver目標文件
// file path
static var filePath : String{
let url = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first
return url!.appendingPathComponent("Data").path
}
// save locally
static func saveData(reviewDaysArray : [MyObjects]){
NSKeyedArchiver.archiveRootObject(reviewDaysArray, toFile: filePath)
}
// get local data
static func getData() -> [MyObjects]{
if let data = NSKeyedUnarchiver.unarchiveObject(withFile: filePath) as? [MyObjects]{
return data
}
return [MyObjects]()
}
用戶是否可以導出NSKeyedArchiver對象,然後在必要時還原?