Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

removed unarchiveTopLevelObjectWithData deprecation #2176

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions DuckDuckGo/TabsModelPersistenceExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
//

import Foundation
import Core
import Common

extension TabsModel {

Expand All @@ -26,17 +28,33 @@ extension TabsModel {
}

public static func get() -> TabsModel? {
guard let data = UserDefaults.app.object(forKey: Constants.key) as? Data else { return nil }
return try? NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? TabsModel
guard let data = UserDefaults.app.object(forKey: Constants.key) as? Data else {
return nil
}
var tabsModel: TabsModel?
do {
let unarchiver = try NSKeyedUnarchiver(forReadingFrom: data)
unarchiver.requiresSecureCoding = false
tabsModel = unarchiver.decodeObject(of: self, forKey: NSKeyedArchiveRootObjectKey)
if let error = unarchiver.error {
throw error
}
} catch {
os_log("Something went wrong unarchiving TabsModel %@", log: .generalLog, type: .error, error.localizedDescription)
}
return tabsModel
}

public static func clear() {
UserDefaults.app.removeObject(forKey: Constants.key)
}

func save() {
guard let data = try? NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false) else { return }
UserDefaults.app.set(data, forKey: Constants.key)
do {
let data = try NSKeyedArchiver.archivedData(withRootObject: self, requiringSecureCoding: false)
UserDefaults.app.set(data, forKey: Constants.key)
} catch {
os_log("Something went wrong archiving TabsModel %@", log: .generalLog, type: .error, error.localizedDescription)
}
}

}
Loading