Skip to content

Commit 54a50ca

Browse files
committed
Add new user defaults keys
1 parent e11857c commit 54a50ca

2 files changed

Lines changed: 38 additions & 0 deletions

File tree

Core/Sources/Preferences/Keys.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@ public struct UserDefaultPreferenceKeys {
133133
public var forceOrderWidgetToFront: HideCommonPrecedingSpacesInSuggestion {
134134
.init()
135135
}
136+
137+
public struct DisableSuggestionFeatureGlobally: UserDefaultPreferenceKey {
138+
public let defaultValue = false
139+
public let key = "DisableSuggestionFeatureGlobally"
140+
}
141+
142+
public var disableSuggestionFeatureGlobally: DisableSuggestionFeatureGlobally {
143+
.init()
144+
}
145+
146+
public struct SuggestionFeatureEnabledProjectList: UserDefaultPreferenceKey {
147+
public let defaultValue: [String] = []
148+
public let key = "SuggestionFeatureEnabledProjectList"
149+
}
150+
151+
public var suggestionFeatureEnabledProjectList: SuggestionFeatureEnabledProjectList {
152+
.init()
153+
}
136154

137155
public var disableLazyVStack: FeatureFlags.DisableLazyVStack { .init() }
138156
}

Core/Sources/Preferences/UserDefaults.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,26 @@ extension String: UserDefaultsStorable {}
2222
extension Data: UserDefaultsStorable {}
2323
extension URL: UserDefaultsStorable {}
2424

25+
extension Array: RawRepresentable where Element: Codable {
26+
public init?(rawValue: String) {
27+
guard let data = rawValue.data(using: .utf8),
28+
let result = try? JSONDecoder().decode([Element].self, from: data)
29+
else {
30+
return nil
31+
}
32+
self = result
33+
}
34+
35+
public var rawValue: String {
36+
guard let data = try? JSONEncoder().encode(self),
37+
let result = String(data: data, encoding: .utf8)
38+
else {
39+
return "[]"
40+
}
41+
return result
42+
}
43+
}
44+
2545
public extension UserDefaults {
2646
// MARK: - Normal Types
2747

0 commit comments

Comments
 (0)