diff --git a/Example.swiftpm/ViewModel.swift b/Example.swiftpm/ViewModel.swift index d0581d6..ea370fa 100644 --- a/Example.swiftpm/ViewModel.swift +++ b/Example.swiftpm/ViewModel.swift @@ -12,6 +12,9 @@ import Combine final class ViewModel: ObservableObject { @Published var contentText: String + @SwiftyRemoteConfig(keyPath: \.contentText) + var fuga: String + private var cancellables: Set = [] init() { @@ -25,3 +28,11 @@ final class ViewModel: ObservableObject { .store(in: &cancellables) } } + +final class Foo { + init() { + let viewModel = ViewModel() + + let foo = viewModel.$fuga.lastFetchTime + } +} diff --git a/README.md b/README.md index a656a4f..bd5402c 100644 --- a/README.md +++ b/README.md @@ -358,14 +358,18 @@ You can also check property details with projected value: ```swift struct Settings { - @SwiftyRemoteConfig(keyPath: \.userColorScheme) - var userColorScheme: String - - var isFetchedOnce: Bool { - // you can also use `_userColorScheme.lastFetchStatus` - return _userColorScheme.lastFetchTime != nil - } + @SwiftyRemoteConfig(keyPath: \.newFeatureAvailable) + var newFeatureAvailable: String } + +struct NewFeatureRouter { + func show(with settings: Settings) { + if settings.$newFeatureAvailable.lastFetchTime != nil { + // show new feature + } else { + // fetch and activate remote config before routing + } + } } ``` diff --git a/Sources/SwiftyRemoteConfig/PropertyWrappers.swift b/Sources/SwiftyRemoteConfig/PropertyWrappers.swift index 184334f..9c78f0c 100644 --- a/Sources/SwiftyRemoteConfig/PropertyWrappers.swift +++ b/Sources/SwiftyRemoteConfig/PropertyWrappers.swift @@ -40,13 +40,13 @@ public final class SwiftyRemoteConfig where T.T == return self.config.lastFetchTime } - public var projectedValue: T { + public var projectedValue: SwiftyRemoteConfig { get { - return self.wrappedValue + return self } - @available(*, unavailable, message: "SwiftyRemoteConfig property wrapper does not support setting values yet.") + @available(*, unavailable, message: "SwiftyRemoteConfig's projected value does not support setting values yet.") set { - fatalError("SwiftyRemoteConfig property wrapper does not support setting values yet.") + fatalError("SwiftyRemoteConfig's projected value does not support setting values yet.") } }