diff --git a/FirebaseRemoteConfigSwift/Sources/PropertyWrapper/RemoteConfigValueObservable.swift b/FirebaseRemoteConfigSwift/Sources/PropertyWrapper/RemoteConfigValueObservable.swift index b35c1685883..b903a65b0ad 100644 --- a/FirebaseRemoteConfigSwift/Sources/PropertyWrapper/RemoteConfigValueObservable.swift +++ b/FirebaseRemoteConfigSwift/Sources/PropertyWrapper/RemoteConfigValueObservable.swift @@ -37,19 +37,13 @@ internal class RemoteConfigValueObservable: ObservableObject { self.key = key remoteConfig = RemoteConfig.remoteConfig() self.fallbackValue = fallbackValue + // Initialize with fallback value configValue = fallbackValue + // Check cached remote config value - do { - let configValue: RemoteConfigValue = remoteConfig[key] - if configValue.source == .remote || configValue.source == .default { - self.configValue = try remoteConfig[key].decoded() - } else { - self.configValue = fallbackValue - } - } catch { - configValue = fallbackValue - } + applyConfigValue() + NotificationCenter.default.addObserver( self, selector: #selector(configDidActivate), name: .onRemoteConfigActivated, object: nil ) @@ -61,13 +55,19 @@ internal class RemoteConfigValueObservable: ObservableObject { if FirebaseApp.app()?.name != appName { return } + applyConfigValue() + } + + private func applyConfigValue() { do { let configValue: RemoteConfigValue = remoteConfig[key] - if configValue.source == .remote { + if configValue.source == .remote || configValue.source == .default { self.configValue = try remoteConfig[key].decoded() + } else { + self.configValue = fallbackValue } } catch { - // Suppresses a hard failure if decoding failed. + configValue = fallbackValue } } }