Unarchive Array with NSKeyedUnarchiver unarchivedObject(ofClass:from:)

后端 未结 6 2050
别跟我提以往
别跟我提以往 2020-12-03 10:58

Since upgrading to Swift 4.2 I\'ve found that many of the NSKeyedUnarchiver and NSKeyedArchiver methods have been deprecated and we must now use the type method static

6条回答
  •  借酒劲吻你
    2020-12-03 11:23

    Swift 5- IOS 13

    guard let mainData = UserDefaults.standard.object(forKey: "eventDetail") as? NSData
    else {
        print(" data not found in UserDefaults")
        return
    }
    do {
        guard let finalArray =
        try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(mainData as Data) as? [EventDetail]
        else {
            return
        }
        self.eventDetail = finalArray
    }
    

提交回复
热议问题