launchdarkly / ios-client-sdk

LaunchDarkly Client-side SDK for iOS (Swift and Obj-C)
https://docs.launchdarkly.com/sdk/client-side/ios
Other
68 stars 84 forks source link

Add support for a dataVariation #275

Closed mcmurrym closed 4 months ago

mcmurrym commented 2 years ago

Add times it would be nice if we could just get back a Data or representation of the value that is stored for a variation. This would help with https://github.com/launchdarkly/ios-client-sdk/issues/274.

Something like...

public func dataVariation<T: Decodable>(forKey flagKey: LDFlagKey, defaultValue: T) -> T {
    variationDetailInternal(flagKey, defaultValue, needsReason: false).value
}
public func dataVariationDetail<T: Decodable>(forKey flagKey: LDFlagKey, defaultValue: T) -> LDEvaluationDetail<T> {
    variationDetailInternal(flagKey, defaultValue, needsReason: true)
}
public func dataVariation(forKey flagKey: LDFlagKey, defaultValue: Data) -> Data {
    variationDetailInternal(flagKey, defaultValue, needsReason: false).value
}
public func dataVariationDetail(forKey flagKey: LDFlagKey, defaultValue: Data) -> LDEvaluationDetail<Data> {
    variationDetailInternal(flagKey, defaultValue, needsReason: true)
}

I would be more than happy to help create the solution, but because LDValue goes as deep as it does, it would take some non-insignificant changes.

mkambale commented 2 years ago

@mcmurrym I am badly struck in extracting the values. Please help me with this. I am using LaunchDarkly 6.0 and getting flag value as a dictionary. I am facing problem in reading the values from flag. This is how I am getting flag value from server -

    let arrayValue = LDClient.get()!.jsonVariationDetail(forKey: forFlag, defaultValue: ["enabled": false])

And, I get this response -

Screenshot 2022-07-15 at 2 44 36 PM

My problem is how do I read the values from arrayValue.value ? I need to make certain changes depending on the values from dictionary. cc: @@louis-launchdarkly

louis-launchdarkly commented 2 years ago

Given this is a solution suggestion for the concern in #274, we will keep the discussion there for now.

brianmichel commented 6 months ago

I just ran into this issue as well, and it's a big bummer that LD does not make these values easily codable. It would be great if they were just parsed out as a regular set of struct as needed @louis-launchdarkly

keelerm84 commented 4 months ago

We just released v9.4.0 which adds two new methods variation<T> and variationDetail<T>! Both of these methods accept a type that must be Decodable and implement our LDValueConvertible protocol (required for now to deal with some internal plumbing).