|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 | 16 |
|
17 |
| -import SwiftUI |
18 | 17 | import FirebaseRemoteConfig
|
| 18 | +import SwiftUI |
19 | 19 |
|
20 |
| -/// A property wrapper that listens to a Remote Config value. |
21 |
| -@available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 14.0, watchOS 7.0, *) |
22 |
| -@propertyWrapper |
23 |
| -public struct RemoteConfigProperty<T: Decodable>: DynamicProperty { |
24 |
| - @State private var configValueObserver: RemoteConfigValueObservable<T> |
| 20 | +#if compiler(>=5.5.2) && canImport(SwiftUI) && (arch(arm64) || arch(x86_64)) |
| 21 | + /// A property wrapper that listens to a Remote Config value. |
| 22 | + @available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 14.0, watchOS 7.0, *) |
| 23 | + @propertyWrapper |
| 24 | + public struct RemoteConfigProperty<T: Decodable>: DynamicProperty { |
| 25 | + @State private var configValueObserver: RemoteConfigValueObservable<T> |
25 | 26 |
|
26 |
| - /// Remote Config key name for this property |
27 |
| - public let key: String |
| 27 | + /// Remote Config key name for this property |
| 28 | + public let key: String |
28 | 29 |
|
29 |
| - /// Remote Config instance for this property |
30 |
| - public let remoteConfig: RemoteConfig |
| 30 | + /// Remote Config instance for this property |
| 31 | + public let remoteConfig: RemoteConfig |
31 | 32 |
|
32 |
| - /// Last fetched status of remote config values |
33 |
| - public var lastFetchStatus: RemoteConfigFetchStatus { |
34 |
| - return remoteConfig.lastFetchStatus |
35 |
| - } |
| 33 | + /// Last fetched status of remote config values |
| 34 | + public var lastFetchStatus: RemoteConfigFetchStatus { |
| 35 | + return remoteConfig.lastFetchStatus |
| 36 | + } |
36 | 37 |
|
37 |
| - /// Last fetched time of remote config values |
38 |
| - public var lastFetchTime: Date? { |
39 |
| - return remoteConfig.lastFetchTime |
40 |
| - } |
| 38 | + /// Last fetched time of remote config values |
| 39 | + public var lastFetchTime: Date? { |
| 40 | + return remoteConfig.lastFetchTime |
| 41 | + } |
41 | 42 |
|
42 |
| - public var wrappedValue: T { |
43 |
| - configValueObserver.configValue |
44 |
| - } |
| 43 | + public var wrappedValue: T { |
| 44 | + configValueObserver.configValue |
| 45 | + } |
45 | 46 |
|
46 |
| - /// Creates an instance by defining key. |
47 |
| - /// This property depends on default remote config. |
48 |
| - /// |
49 |
| - /// - Parameter key: key name |
50 |
| - public init(forKey key: String) { |
51 |
| - self.key = key |
52 |
| - remoteConfig = RemoteConfig.remoteConfig() |
| 47 | + /// Creates an instance by defining key. |
| 48 | + /// This property depends on default remote config. |
| 49 | + /// |
| 50 | + /// - Parameter key: key name |
| 51 | + public init(forKey key: String) { |
| 52 | + self.key = key |
| 53 | + remoteConfig = RemoteConfig.remoteConfig() |
53 | 54 |
|
54 |
| - _configValueObserver = State( |
55 |
| - wrappedValue: RemoteConfigValueObservable<T>( |
56 |
| - key: key, |
57 |
| - remoteConfig: RemoteConfig.remoteConfig() |
| 55 | + _configValueObserver = State( |
| 56 | + wrappedValue: RemoteConfigValueObservable<T>( |
| 57 | + key: key, |
| 58 | + remoteConfig: RemoteConfig.remoteConfig() |
| 59 | + ) |
58 | 60 | )
|
59 |
| - ) |
60 |
| - } |
| 61 | + } |
61 | 62 |
|
62 |
| - /// Creates an instance by defining key and remote config instance. |
63 |
| - /// |
64 |
| - /// - Parameters: |
65 |
| - /// - key: key name |
66 |
| - /// - remoteConfig: remote config instance |
67 |
| - public init(forKey key: String, |
68 |
| - remoteConfig: RemoteConfig) { |
69 |
| - self.key = key |
70 |
| - self.remoteConfig = remoteConfig |
| 63 | + /// Creates an instance by defining key and remote config instance. |
| 64 | + /// |
| 65 | + /// - Parameters: |
| 66 | + /// - key: key name |
| 67 | + /// - remoteConfig: remote config instance |
| 68 | + public init(forKey key: String, |
| 69 | + remoteConfig: RemoteConfig) { |
| 70 | + self.key = key |
| 71 | + self.remoteConfig = remoteConfig |
71 | 72 |
|
72 |
| - _configValueObserver = State( |
73 |
| - wrappedValue: RemoteConfigValueObservable<T>( |
74 |
| - key: key, |
75 |
| - remoteConfig: remoteConfig |
| 73 | + _configValueObserver = State( |
| 74 | + wrappedValue: RemoteConfigValueObservable<T>( |
| 75 | + key: key, |
| 76 | + remoteConfig: remoteConfig |
| 77 | + ) |
76 | 78 | )
|
77 |
| - ) |
| 79 | + } |
78 | 80 | }
|
79 |
| -} |
| 81 | +#endif |
0 commit comments