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

Warnings: unarchiveObject(with data: Data) deprecated since iOS 12.0 #265

Open
ragu-pdx opened this issue Oct 22, 2020 · 1 comment
Open

Comments

@ragu-pdx
Copy link

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
    }
}
@Ged2323
Copy link

Ged2323 commented Dec 8, 2020

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. -> "."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants