【问题标题】:NSKeyedArchiver how should i set path in iOS12NSKeyedArchiver 我应该如何在 iOS12 中设置路径
【发布时间】:2018-10-22 07:52:18
【问题描述】:
let person = Person()
    person.name = "zhangzhe"
    person.age = 25
    print(self.home)
    do {
        try NSKeyedArchiver.archivedData(withRootObject: person, requiringSecureCoding: false)
    } catch {
        print(error)
    }

我想设置路径,以便我可以再次找到它。 但我不知道该怎么办.. archiveRootObject(_ rootObject: Any, toFile path: String) 该方法在iOS12中已弃用

【问题讨论】:

    标签: nskeyedarchiver


    【解决方案1】:

    这可能对 iOS12 有帮助

    do {
      let data = try NSKeyedArchiver.archivedData(withRootObject: person, requiringSecureCoding: false)
      try data.write(to: url)
    } catch {
      print("Couldn't write file")
    }
    

    【讨论】:

      猜你喜欢
      • 2018-07-07
      • 2019-11-28
      • 1970-01-01
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 2019-09-28
      • 2011-08-11
      • 1970-01-01
      相关资源
      最近更新 更多