SwiftyUserDefaults
SwiftyUserDefaults copied to clipboard
Warnings: unarchiveObject(with data: Data) deprecated since iOS 12.0
Getting warnings pointing to this deprecation:
@available(iOS, introduced: 2.0, deprecated: 12.0, message: "Use +unarchivedObjectOfClass:fromData:error: instead")
open class func unarchiveObject(withFile path: String) -> Any?
being called from:
public struct DefaultsUrlBridge: DefaultsBridge {
public func deserialize(_ object: Any) -> URL? {
if let object = object as? URL {
return object
}
if let object = object as? Data {
return NSKeyedUnarchiver.unarchiveObject(with: object) as? URL
}
if let object = object as? NSString {
let path = object.expandingTildeInPath
return URL(fileURLWithPath: path)
}
return nil
}
}
and twice in this struct:
public struct DefaultsKeyedArchiverBridge<T>: DefaultsBridge {
public init() {}
public func save(key: String, value: T?, userDefaults: UserDefaults) {
guard let value = value else {
userDefaults.removeObject(forKey: key)
return
}
// Needed because Quick/Nimble have min target 10.10...
if #available(OSX 10.11, *) {
userDefaults.set(NSKeyedArchiver.archivedData(withRootObject: value), forKey: key)
} else {
fatalError("Shouldn't really happen. We do not support macOS 10.10, if it happened to you please report your use-case on GitHub issues.")
}
}
public func get(key: String, userDefaults: UserDefaults) -> T? {
guard let data = userDefaults.data(forKey: key) else {
return nil
}
return deserialize(data)
}
public func deserialize(_ object: Any) -> T? {
guard let data = object as? Data else { return nil }
return NSKeyedUnarchiver.unarchiveObject(with: data) as? T
}
}
This is also creating a problem in a project I just started.
All of a sudden my project would just freeze the build for no reason or breakpoint.
I swapped all the defaults out with https://github.com/sindresorhus/Defaults project as it is a similar way the default Keys are created.
This worked though if you've got a big project it would be a pain. There is something in Swifty that is causing a hang when building.
Something to do with maybe the syntax when using the keys. -> "."