Unarchive Array with NSKeyedUnarchiver unarchivedObject(ofClass:from:)

后端 未结 6 2059
别跟我提以往
别跟我提以往 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:09

    You are likely looking for this:

    if let widgetsData = UserDefaults.standard.data(forKey: USER_DEFAULTS_KEY_WIDGET_DATA) {
            if let widgets = (try? NSKeyedUnarchiver.unarchivedObject(ofClasses: [NSArray.self, WidgetData.self], from: widgetsData)) as? [WidgetData] {
                // your code
            }
        }
    

提交回复
热议问题