Skip to content

Commit 327c4a7

Browse files
committed
[#639] Resolve comments
1 parent 4dcf24f commit 327c4a7

7 files changed

Lines changed: 26 additions & 16 deletions

File tree

template/Modules/Data/Sources/AppConfig/AnyCodingKey.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ public struct AnyCodingKey: CodingKey, Hashable {
2828
self.init(stringValue: base.stringValue)
2929
}
3030
}
31-
}
31+
}

template/Modules/Data/Sources/AppConfig/AppConfig.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,4 @@ extension AppConfig {
121121
#endif
122122
return true
123123
}
124-
}
124+
}

template/Modules/Data/Sources/AppConfig/AppDefaultConfig.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import Foundation
77
/// Wraps an arbitrary key-value dictionary to be loaded as Firebase Remote Config defaults.
88
public struct AppDefaultConfig: Encodable {
99

10-
public var configs: [AnyCodingKey: any Encodable]
10+
public let configs: [AnyCodingKey: any Encodable]
1111

1212
public init(configs: [AnyCodingKey: any Encodable] = [:]) {
1313
self.configs = configs
@@ -45,4 +45,4 @@ private struct AnyEncodable: Encodable {
4545
func encode(to encoder: any Encoder) throws {
4646
try value.encode(to: encoder)
4747
}
48-
}
48+
}

template/Modules/Data/Sources/AppConfig/ExampleAppConfiguration.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public func createExampleAppConfig() -> AppConfig<ExampleAppConfiguration> {
4646

4747
let configMapper: (RemoteConfigDecoder) -> ExampleAppConfiguration = { decoder in
4848
ExampleAppConfiguration(
49-
isFeatureEnabled: decoder.decodeBool(forKey: ExampleConfigKey.isFeatureEnabled.rawValue),
49+
isFeatureEnabled: decoder.decodeBool(forKey: ExampleConfigKey.isFeatureEnabled.rawValue) ?? false,
5050
maxRetryCount: decoder.decodeNumber(forKey: ExampleConfigKey.maxRetryCount.rawValue)?.intValue ?? 3,
5151
apiTimeout: decoder.decodeNumber(forKey: ExampleConfigKey.apiTimeout.rawValue)?.doubleValue ?? 30.0,
5252
welcomeMessage: decoder.decodeString(forKey: ExampleConfigKey.welcomeMessage.rawValue) ?? "Welcome"
@@ -58,4 +58,4 @@ public func createExampleAppConfig() -> AppConfig<ExampleAppConfiguration> {
5858
initialConfig: initialConfig,
5959
configMapper: configMapper
6060
)
61-
}
61+
}

template/Modules/Data/Sources/AppConfig/FirebaseRemoteConfigSource.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public final class FirebaseRemoteConfigSource: RemoteConfigSource {
3030

3131
private let remoteConfig: any RemoteConfigInterface
3232

33-
public convenience init(remoteConfig: RemoteConfig = RemoteConfig.remoteConfig()) {
33+
public convenience init() {
34+
self.init(config: RemoteConfig.remoteConfig())
35+
}
36+
37+
public convenience init(remoteConfig: RemoteConfig) {
3438
self.init(config: remoteConfig)
3539
}
3640

@@ -53,7 +57,7 @@ public final class FirebaseRemoteConfigSource: RemoteConfigSource {
5357
public func value(forKey key: String) async -> RemoteConfigStoredValue? {
5458
let (data, source) = remoteConfig.configEntry(forKey: key)
5559

56-
guard source != .static || !data.isEmpty else {
60+
guard !data.isEmpty, source != .static else {
5761
return nil
5862
}
5963

template/Modules/Data/Sources/AppConfig/RemoteConfigDecoder.swift

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,24 @@ public struct RemoteConfigDecoder {
5454
return value
5555
}
5656

57-
public func decodeBool(forKey keyString: String) -> Bool {
58-
let value = remoteConfig[keyString].boolValue
57+
public func decodeBool(forKey keyString: String) -> Bool? {
58+
let configValue = remoteConfig[keyString]
59+
guard !configValue.dataValue.isEmpty else {
60+
log("No bool value for key: \(keyString)")
61+
return nil
62+
}
63+
let value = configValue.boolValue
5964
log("Decoded bool for \(keyString): \(value)")
6065
return value
6166
}
6267

6368
public func decodeNumber(forKey keyString: String) -> NSNumber? {
64-
let value = remoteConfig[keyString].numberValue
69+
let configValue = remoteConfig[keyString]
70+
guard !configValue.dataValue.isEmpty else {
71+
log("No number value for key: \(keyString)")
72+
return nil
73+
}
74+
let value = configValue.numberValue
6575
log("Decoded number for \(keyString): \(value)")
6676
return value
6777
}

template/Modules/Data/Sources/Extensions/Container+Data.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,10 @@ extension Container {
4747
.singleton
4848
}
4949

50-
public var firebaseRemoteConfigSource: Factory<FirebaseRemoteConfigSource> {
50+
public var firebaseRemoteConfigSource: Factory<RemoteConfigSource> {
5151
self { FirebaseRemoteConfigSource() }.singleton
5252
}
5353

54-
public var remoteConfigRepository: Factory<RemoteConfigRepository> {
55-
self { DefaultRemoteConfigRepository(source: self.firebaseRemoteConfigSource()) }.singleton
56-
}
57-
5854
/// Example AppConfig factory. Replace with your app-specific configuration.
5955
public var exampleAppConfig: Factory<AppConfig<ExampleAppConfiguration>> {
6056
self { createExampleAppConfig() }.singleton

0 commit comments

Comments
 (0)