gpt4 book ai didi

ios - 如何在 NSUserDefaults 中保存任何类

转载 作者:行者123 更新时间:2023-11-28 11:11:01 25 4
gpt4 key购买 nike

<分区>

我尝试了几种不同的方法来将此类保存在 NSUserDefaults 中。我不知道如何使用覆盖功能保存类。我怎样才能做到?

class CountryEntity: AnyObject {
private(set) var id: UInt = 0
private(set) var name = ""

override func cityData(data: Dictionary<String, AnyObject>!) {
id = data.uint(key: "id")
name = data.string(key: "name")
}

我试过了,但对我没有帮助

  private static var _selectedCountryEntity: AnyObject? = NSUserDefaults.standardUserDefaults().objectForKey(countryNameKey) {
didSet {
let savedData = NSKeyedArchiver.archivedDataWithRootObject(selectedCountryEntity as! NSData)

NSUserDefaults.standardUserDefaults().setObject(savedData, forKey: countryNameKey)
NSUserDefaults.standardUserDefaults().synchronize()
}
}

static var selectedCountryEntity: AnyObject? {
get {
return _selectedCountryEntity
}


set {
// if newValue != _selectedCountryTuple {
_selectedCountryEntity = newValue
// }
}
}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com