Skip to content

Commit

Permalink
swiftformat
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykPiwowarczyk committed Oct 4, 2023
1 parent f937023 commit 4884ab2
Show file tree
Hide file tree
Showing 2 changed files with 953 additions and 916 deletions.
19 changes: 14 additions & 5 deletions Sources/FeaturevisorSDK/Instance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ public struct Evaluation: Codable {
variationValue: VariationValue? = nil,
variableKey: VariableKey? = nil,
variableValue: VariableValue? = nil,
variableSchema: VariableSchema? = nil) {
variableSchema: VariableSchema? = nil
) {

self.featureKey = featureKey
self.reason = reason
Expand Down Expand Up @@ -117,23 +118,31 @@ public struct Evaluation: Codable {
let container = try decoder.container(keyedBy: CodingKeys.self)

featureKey = try container.decode(FeatureKey.self, forKey: .featureKey)
reason = try EvaluationReason(rawValue: container.decode(String.self, forKey: .reason)) ?? .error
reason =
try EvaluationReason(rawValue: container.decode(String.self, forKey: .reason)) ?? .error
bucketValue = try container.decodeIfPresent(BucketValue.self, forKey: .bucketValue)
ruleKey = try? container.decodeIfPresent(RuleKey.self, forKey: .ruleKey)
enabled = try? container.decodeIfPresent(Bool.self, forKey: .enabled)
traffic = try? container.decodeIfPresent(Traffic.self, forKey: .traffic)
sticky = try? container.decodeIfPresent(OverrideFeature.self, forKey: .sticky)
initial = try? container.decodeIfPresent(OverrideFeature.self, forKey: .initial)
variation = try? container.decodeIfPresent(Variation.self, forKey: .variation)
variationValue = try? container.decodeIfPresent(VariationValue.self, forKey: .variationValue)
variationValue = try? container.decodeIfPresent(
VariationValue.self,
forKey: .variationValue
)
variableKey = try? container.decodeIfPresent(VariableKey.self, forKey: .variableKey)
variableValue = try? container.decodeIfPresent(VariableValue.self, forKey: .variableValue)
variableSchema = try? container.decodeIfPresent(VariableSchema.self, forKey: .variableSchema)
variableSchema = try? container.decodeIfPresent(
VariableSchema.self,
forKey: .variableSchema
)
}

func toDictionary() -> [String: Any] {
guard let data = try? JSONEncoder().encode(self) else { return [:] }
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any]} ?? [:]
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments))
.flatMap { $0 as? [String: Any] } ?? [:]
}
}

Expand Down
Loading

0 comments on commit 4884ab2

Please sign in to comment.