sunshinejr / SwiftyUserDefaults

Modern Swift API for NSUserDefaults
http://radex.io/swift/nsuserdefaults/static
MIT License
4.86k stars 367 forks source link

Can I have an OptionSet that is Codable && DefaultsSerializable #258

Closed ConfusedVorlon closed 3 years ago

ConfusedVorlon commented 4 years ago

I have an OptionSet

struct LabelInfo: OptionSet, DefaultsSerializable {
    let rawValue: Int

    static let number = LabelInfo(rawValue: 1 << 0)
    static let person = LabelInfo(rawValue: 1 << 1)

    static let all: LabelInfo = [.number, .person]
    static let none: LabelInfo = []

}

it works fine as DefaultsSerializable

it also works fine as Codable

however if I try to have both Codable && DefaultsSerializable

struct LabelInfo: OptionSet, DefaultsSerializable, Codable {...}

Ambiguous inference of associated type 'Bridge': 'DefaultsCodableBridge' vs. 'DefaultsRawRepresentableBridge'

Matching requirement '_defaults' to this declaration inferred associated type to 'DefaultsCodableBridge'

Matching requirement '_defaults' to this declaration inferred associated type to 'DefaultsRawRepresentableBridge'

is there a way around this?

thank you

sunshinejr commented 4 years ago

hey @ConfusedVorlon - please take a look at https://github.com/sunshinejr/SwiftyUserDefaults/issues/206, it should help! in case it doesn't, please let me know the details so I can help 👍