Skip to content

Commit 722f715

Browse files
committed
Fixed ability to subclass the FlagValueDictionary
1 parent e11cf66 commit 722f715

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

Sources/Vexil/Sources/FlagValueDictionary+FlagValueSource.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ import Combine
1111

1212
extension FlagValueDictionary: FlagValueSource {
1313

14-
public var name: String {
15-
return "\(String(describing: Self.self)): \(self.id.uuidString)"
16-
}
17-
1814
public func flagValue<Value>(key: String) -> Value? where Value: FlagValue {
1915
guard let value = self.storage[key] else {
2016
return nil

Sources/Vexil/Sources/FlagValueDictionary.swift

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ open class FlagValueDictionary: Identifiable, ExpressibleByDictionaryLiteral, Co
2121
/// A Unique Identifier for this FlagValueDictionary
2222
public let id: UUID
2323

24+
/// The name of our `FlagValueSource`
25+
public var name: String {
26+
return "\(String(describing: Self.self)): \(self.id.uuidString)"
27+
}
28+
2429
/// Our internal dictionary type
2530
public typealias DictionaryType = [String: BoxedFlagValue]
2631

@@ -39,13 +44,19 @@ open class FlagValueDictionary: Identifiable, ExpressibleByDictionaryLiteral, Co
3944
self.storage = storage
4045
}
4146

47+
/// Initialises an empty `FlagValueDictionary`
48+
public init() {
49+
self.id = UUID()
50+
self.storage = [:]
51+
}
52+
4253
/// Initialises a `FlagValueDictionary` with the specified dictionary
4354
///
44-
public convenience init (_ dictionary: DictionaryType = [:]) {
45-
self.init(
46-
id: UUID(),
47-
storage: dictionary
48-
)
55+
public required init<S> (_ sequence: S) where S: Sequence, S.Element == (key: String, value: BoxedFlagValue) {
56+
self.id = UUID()
57+
self.storage = sequence.reduce(into: [:]) { dict, pair in
58+
dict.updateValue(pair.value, forKey: pair.key)
59+
}
4960
}
5061

5162
/// Initialises a `FlagValueDictionary` using a dictionary literal

0 commit comments

Comments
 (0)