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

How to support existing types with different bridges #287

Open
jifang opened this issue Feb 7, 2022 · 0 comments
Open

How to support existing types with different bridges #287

jifang opened this issue Feb 7, 2022 · 0 comments

Comments

@jifang
Copy link

jifang commented Feb 7, 2022

In the README, there is an example to support existing types with different bridges, you can extend it similarly:

extension Data: DefaultsSerializable {
    public static var _defaultsArray: DefaultsArrayBridge<[T]> { DefaultsArrayBridge() }
    public static var _defaults: DefaultsDataBridge { DefaultsDataBridge() }
}

However, saying if I'd like to use a different bridge on Data type. For example,

public struct MyDataBridge: DefaultsBridge {

    public init() {}

    public func save(key: String, value: Data?, userDefaults: UserDefaults) {
        // Do nothing
    }

    public func get(key: String, userDefaults: UserDefaults) -> Data? {
        return nil
    }

    public func deserialize(_ object: Any) -> Data? {
        return nil
    }
}

extension Data: DefaultsSerializable {
    public static var _defaults: MyDataBridge { MyDataBridge() }
}

I will get the compilation warning of Conformance of 'Data' to protocol 'DefaultsSerializable' was already stated in the protocol's module 'SwiftyUserDefaults'. So is it even possible to change the bridge for types that have already been implemented in the module?

Thanks

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

1 participant