// // ShareProfsUtil.swift // iOSFirst // // Created by 孙宇峰 on 2023/3/1. // import Foundation import HandyJSON extension UserDefaults{ func saveCustomObject(customObject object: NSData, key: String) { //2 let encodedObject = NSKeyedArchiver.archivedData(withRootObject: object) self.set(encodedObject, forKey: key) self.synchronize() } func getCustomObject(forKey key: String) -> T? { //3 let decodedObject = self.object(forKey: key) as! Data let object = NSKeyedUnarchiver.unarchiveObject(with: decodedObject ) return object as? T } }