Skip to content

Commit 8cf2e02

Browse files
authored
[Config] Consolidate getters and setters UserDefaultsManager.swift (#14040)
1 parent da081ec commit 8cf2e02

File tree

2 files changed

+130
-184
lines changed

2 files changed

+130
-184
lines changed

.github/workflows/remoteconfig.yml

Lines changed: 54 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -104,60 +104,60 @@ jobs:
104104
# path: .build
105105
# key: ${{ steps.generate_cache_key.outputs.cache_key }}
106106

107-
spm:
108-
# Don't run on private repo unless it is a PR.
109-
if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'
110-
needs: [spm-package-resolved]
111-
strategy:
112-
matrix:
113-
include:
114-
- os: macos-13
115-
xcode: Xcode_15.2
116-
target: iOS
117-
test: spm
118-
- os: macos-14
119-
xcode: Xcode_15.4
120-
target: iOS
121-
test: spm
122-
- os: macos-15
123-
xcode: Xcode_16
124-
target: iOS
125-
test: spm
126-
- os: macos-15
127-
xcode: Xcode_16
128-
target: tvOS
129-
test: spm
130-
- os: macos-15
131-
xcode: Xcode_16
132-
target: macOS
133-
test: spm
134-
- os: macos-15
135-
xcode: Xcode_16
136-
target: watchOS
137-
test: spmbuildonly
138-
- os: macos-15
139-
xcode: Xcode_16
140-
target: catalyst
141-
test: spm
142-
- os: macos-15
143-
xcode: Xcode_16
144-
target: visionOS
145-
test: spm
146-
runs-on: ${{ matrix.os }}
147-
steps:
148-
- uses: actions/checkout@v4
149-
- uses: actions/cache/restore@v4
150-
with:
151-
path: .build
152-
key: ${{needs.spm-package-resolved.outputs.cache_key}}
153-
- name: Xcode
154-
run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app/Contents/Developer
155-
- name: Initialize xcodebuild
156-
run: scripts/setup_spm_tests.sh
157-
- name: Unit Tests
158-
run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigUnit ${{ matrix.target }} spm
159-
- name: Fake Console tests
160-
run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigFakeConsole ${{ matrix.target }} ${{ matrix.test }}
107+
# spm:
108+
# # Don't run on private repo unless it is a PR.
109+
# if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'
110+
# needs: [spm-package-resolved]
111+
# strategy:
112+
# matrix:
113+
# include:
114+
# - os: macos-13
115+
# xcode: Xcode_15.2
116+
# target: iOS
117+
# test: spm
118+
# - os: macos-14
119+
# xcode: Xcode_15.4
120+
# target: iOS
121+
# test: spm
122+
# - os: macos-15
123+
# xcode: Xcode_16
124+
# target: iOS
125+
# test: spm
126+
# - os: macos-15
127+
# xcode: Xcode_16
128+
# target: tvOS
129+
# test: spm
130+
# - os: macos-15
131+
# xcode: Xcode_16
132+
# target: macOS
133+
# test: spm
134+
# - os: macos-15
135+
# xcode: Xcode_16
136+
# target: watchOS
137+
# test: spmbuildonly
138+
# - os: macos-15
139+
# xcode: Xcode_16
140+
# target: catalyst
141+
# test: spm
142+
# - os: macos-15
143+
# xcode: Xcode_16
144+
# target: visionOS
145+
# test: spm
146+
# runs-on: ${{ matrix.os }}
147+
# steps:
148+
# - uses: actions/checkout@v4
149+
# - uses: actions/cache/restore@v4
150+
# with:
151+
# path: .build
152+
# key: ${{needs.spm-package-resolved.outputs.cache_key}}
153+
# - name: Xcode
154+
# run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app/Contents/Developer
155+
# - name: Initialize xcodebuild
156+
# run: scripts/setup_spm_tests.sh
157+
# - name: Unit Tests
158+
# run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigUnit ${{ matrix.target }} spm
159+
# - name: Fake Console tests
160+
# run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigFakeConsole ${{ matrix.target }} ${{ matrix.test }}
161161

162162
catalyst:
163163
# Don't run on private repo unless it is a PR.

FirebaseRemoteConfig/SwiftNew/UserDefaultsManager.swift

Lines changed: 76 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -102,182 +102,128 @@ public class UserDefaultsManager: NSObject {
102102

103103
/// The last ETag received from the server.
104104
@objc public var lastETag: String? {
105-
return instanceUserDefaults[kRCNUserDefaultsKeyNamelastETag] as? String
106-
}
107-
108-
/// Sets the last ETag received from the server.
109-
///
110-
/// - Parameter lastETag: The last ETag received from the server.
111-
@objc public func setLastETag(_ lastETag: String?) {
112-
if let lastETag = lastETag {
113-
setInstanceUserDefaultsValue(lastETag, forKey: kRCNUserDefaultsKeyNamelastETag)
105+
get { instanceUserDefaults[kRCNUserDefaultsKeyNamelastETag] as? String }
106+
set {
107+
if let lastETag = newValue {
108+
setInstanceUserDefaultsValue(lastETag, forKey: kRCNUserDefaultsKeyNamelastETag)
109+
}
114110
}
115111
}
116112

117113
/// The last fetched template version.
118114
@objc public var lastFetchedTemplateVersion: String {
119-
return instanceUserDefaults[ConfigConstants.fetchResponseKeyTemplateVersion] as? String ?? "0"
120-
}
121-
122-
/// Sets the last fetched template version.
123-
///
124-
/// - Parameter templateVersion: The last fetched template version.
125-
@objc public func setLastFetchedTemplateVersion(_ templateVersion: String) {
126-
setInstanceUserDefaultsValue(
127-
templateVersion,
128-
forKey: ConfigConstants.fetchResponseKeyTemplateVersion
129-
)
115+
get { instanceUserDefaults[ConfigConstants.fetchResponseKeyTemplateVersion] as? String ?? "0" }
116+
set {
117+
setInstanceUserDefaultsValue(
118+
newValue,
119+
forKey: ConfigConstants.fetchResponseKeyTemplateVersion
120+
)
121+
}
130122
}
131123

132124
/// The last active template version.
133125
@objc public var lastActiveTemplateVersion: String {
134-
return instanceUserDefaults[ConfigConstants.activeKeyTemplateVersion] as? String ?? "0"
135-
}
136-
137-
/// Sets the last active template version.
138-
///
139-
/// - Parameter templateVersion: The last active template version.
140-
@objc public func setLastActiveTemplateVersion(_ templateVersion: String) {
141-
setInstanceUserDefaultsValue(templateVersion, forKey: ConfigConstants.activeKeyTemplateVersion)
126+
get { instanceUserDefaults[ConfigConstants.activeKeyTemplateVersion] as? String ?? "0" }
127+
set {
128+
setInstanceUserDefaultsValue(newValue, forKey: ConfigConstants.activeKeyTemplateVersion)
129+
}
142130
}
143131

144132
/// The last ETag update time.
145133
@objc public var lastETagUpdateTime: TimeInterval {
146-
return instanceUserDefaults[kRCNUserDefaultsKeyNamelastETagUpdateTime] as? TimeInterval ?? 0
147-
}
148-
149-
/// Sets the last ETag update time.
150-
///
151-
/// - Parameter lastETagUpdateTime: The last ETag update time.
152-
@objc public func setLastETagUpdateTime(_ lastETagUpdateTime: TimeInterval) {
153-
setInstanceUserDefaultsValue(
154-
lastETagUpdateTime,
155-
forKey: kRCNUserDefaultsKeyNamelastETagUpdateTime
156-
)
134+
get { instanceUserDefaults[kRCNUserDefaultsKeyNamelastETagUpdateTime] as? TimeInterval ?? 0 }
135+
set {
136+
setInstanceUserDefaultsValue(newValue, forKey: kRCNUserDefaultsKeyNamelastETagUpdateTime)
137+
}
157138
}
158139

159140
/// The last fetch time.
160141
@objc public var lastFetchTime: TimeInterval {
161-
return instanceUserDefaults[kRCNUserDefaultsKeyNameLastSuccessfulFetchTime] as? TimeInterval ??
162-
0
163-
}
164-
165-
/// Sets the last fetch time.
166-
///
167-
/// - Parameter lastFetchTime: The last fetch time.
168-
@objc public func setLastFetchTime(_ lastFetchTime: TimeInterval) {
169-
setInstanceUserDefaultsValue(
170-
lastFetchTime,
171-
forKey: kRCNUserDefaultsKeyNameLastSuccessfulFetchTime
172-
)
142+
get {
143+
instanceUserDefaults[kRCNUserDefaultsKeyNameLastSuccessfulFetchTime] as? TimeInterval ?? 0
144+
}
145+
set {
146+
setInstanceUserDefaultsValue(newValue, forKey: kRCNUserDefaultsKeyNameLastSuccessfulFetchTime)
147+
}
173148
}
174149

175150
/// The last fetch status.
176151
@objc public var lastFetchStatus: String? {
177-
return instanceUserDefaults[kRCNUserDefaultsKeyNamelastFetchStatus] as? String
178-
}
179-
180-
/// Sets the last fetch status.
181-
///
182-
/// - Parameter lastFetchStatus: The last fetch status.
183-
@objc public func setLastFetchStatus(_ lastFetchStatus: String?) {
184-
if let lastFetchStatus = lastFetchStatus {
185-
setInstanceUserDefaultsValue(lastFetchStatus, forKey: kRCNUserDefaultsKeyNamelastFetchStatus)
152+
get { instanceUserDefaults[kRCNUserDefaultsKeyNamelastFetchStatus] as? String }
153+
set {
154+
if let lastFetchStatus = newValue {
155+
setInstanceUserDefaultsValue(
156+
lastFetchStatus,
157+
forKey: kRCNUserDefaultsKeyNamelastFetchStatus
158+
)
159+
}
186160
}
187161
}
188162

189163
/// Whether the client is throttled with exponential backoff.
190164
@objc public var isClientThrottledWithExponentialBackoff: Bool {
191-
return instanceUserDefaults[kRCNUserDefaultsKeyNameIsClientThrottled] as? Bool ?? false
192-
}
193-
194-
/// Sets whether the client is throttled with exponential backoff.
195-
///
196-
/// - Parameter isThrottledWithExponentialBackoff: Whether the client is throttled with
197-
/// exponential backoff.
198-
@objc public func setIsClientThrottledWithExponentialBackoff(_ isThrottledWithExponentialBackoff: Bool) {
199-
setInstanceUserDefaultsValue(
200-
isThrottledWithExponentialBackoff,
201-
forKey: kRCNUserDefaultsKeyNameIsClientThrottled
202-
)
165+
get { instanceUserDefaults[kRCNUserDefaultsKeyNameIsClientThrottled] as? Bool ?? false }
166+
set {
167+
setInstanceUserDefaultsValue(
168+
newValue,
169+
forKey: kRCNUserDefaultsKeyNameIsClientThrottled
170+
)
171+
}
203172
}
204173

205174
/// The throttle end time.
206175
@objc public var throttleEndTime: TimeInterval {
207-
return instanceUserDefaults[kRCNUserDefaultsKeyNameThrottleEndTime] as? TimeInterval ?? 0
208-
}
209-
210-
/// Sets the throttle end time.
211-
///
212-
/// - Parameter throttleEndTime: The throttle end time.
213-
@objc public func setThrottleEndTime(_ throttleEndTime: TimeInterval) {
214-
setInstanceUserDefaultsValue(throttleEndTime, forKey: kRCNUserDefaultsKeyNameThrottleEndTime)
176+
get { instanceUserDefaults[kRCNUserDefaultsKeyNameThrottleEndTime] as? TimeInterval ?? 0 }
177+
set {
178+
setInstanceUserDefaultsValue(newValue, forKey: kRCNUserDefaultsKeyNameThrottleEndTime)
179+
}
215180
}
216181

217182
/// The current throttling retry interval in seconds.
218183
@objc public var currentThrottlingRetryIntervalSeconds: TimeInterval {
219-
return instanceUserDefaults[
220-
kRCNUserDefaultsKeyNameCurrentThrottlingRetryInterval
221-
] as? TimeInterval ??
222-
0
223-
}
224-
225-
/// Sets the current throttling retry interval in seconds.
226-
///
227-
/// - Parameter throttlingRetryIntervalSeconds: The current throttling retry interval in seconds.
228-
@objc public func setCurrentThrottlingRetryIntervalSeconds(_ throttlingRetryIntervalSeconds: TimeInterval) {
229-
setInstanceUserDefaultsValue(
230-
throttlingRetryIntervalSeconds,
231-
forKey: kRCNUserDefaultsKeyNameCurrentThrottlingRetryInterval
232-
)
184+
get {
185+
instanceUserDefaults[
186+
kRCNUserDefaultsKeyNameCurrentThrottlingRetryInterval
187+
] as? TimeInterval ?? 0
188+
}
189+
set {
190+
setInstanceUserDefaultsValue(
191+
newValue, forKey: kRCNUserDefaultsKeyNameCurrentThrottlingRetryInterval
192+
)
193+
}
233194
}
234195

235196
/// The realtime retry count.
236197
@objc public var realtimeRetryCount: Int {
237-
return instanceUserDefaults[kRCNUserDefaultsKeyNameRealtimeRetryCount] as? Int ?? 0
238-
}
239-
240-
/// Sets the realtime retry count.
241-
///
242-
/// - Parameter realtimeRetryCount: The realtime retry count.
243-
@objc public func setRealtimeRetryCount(_ realtimeRetryCount: Int) {
244-
setInstanceUserDefaultsValue(
245-
realtimeRetryCount,
246-
forKey: kRCNUserDefaultsKeyNameRealtimeRetryCount
247-
)
198+
get { instanceUserDefaults[kRCNUserDefaultsKeyNameRealtimeRetryCount] as? Int ?? 0 }
199+
set { setInstanceUserDefaultsValue(newValue, forKey: kRCNUserDefaultsKeyNameRealtimeRetryCount)
200+
}
248201
}
249202

250203
/// The realtime throttle end time.
251204
@objc public var realtimeThrottleEndTime: TimeInterval {
252-
return instanceUserDefaults[kRCNUserDefaultsKeyNameRealtimeThrottleEndTime] as? TimeInterval ??
253-
0
254-
}
255-
256-
/// Sets the realtime throttle end time.
257-
///
258-
/// - Parameter throttleEndTime: The realtime throttle end time.
259-
@objc public func setRealtimeThrottleEndTime(_ throttleEndTime: TimeInterval) {
260-
setInstanceUserDefaultsValue(
261-
throttleEndTime,
262-
forKey: kRCNUserDefaultsKeyNameRealtimeThrottleEndTime
263-
)
205+
get {
206+
instanceUserDefaults[kRCNUserDefaultsKeyNameRealtimeThrottleEndTime] as? TimeInterval ?? 0
207+
}
208+
set {
209+
setInstanceUserDefaultsValue(
210+
newValue, forKey: kRCNUserDefaultsKeyNameRealtimeThrottleEndTime
211+
)
212+
}
264213
}
265214

266215
/// The current realtime throttling retry interval in seconds.
267216
@objc public var currentRealtimeThrottlingRetryIntervalSeconds: TimeInterval {
268-
return instanceUserDefaults[
269-
kRCNUserDefaultsKeyNameCurrentRealtimeThrottlingRetryInterval
270-
] as? TimeInterval ??
271-
0
272-
}
273-
274-
/// Sets the current realtime throttling retry interval in seconds.
275-
///
276-
/// - Parameter throttlingRetryIntervalSeconds: The current realtime throttling retry interval in
277-
/// seconds.
278-
@objc public func setCurrentRealtimeThrottlingRetryIntervalSeconds(_ throttlingRetryIntervalSeconds: TimeInterval) {
279-
setInstanceUserDefaultsValue(throttlingRetryIntervalSeconds,
280-
forKey: kRCNUserDefaultsKeyNameCurrentRealtimeThrottlingRetryInterval)
217+
get {
218+
instanceUserDefaults[
219+
kRCNUserDefaultsKeyNameCurrentRealtimeThrottlingRetryInterval
220+
] as? TimeInterval ?? 0
221+
}
222+
set {
223+
setInstanceUserDefaultsValue(
224+
newValue, forKey: kRCNUserDefaultsKeyNameCurrentRealtimeThrottlingRetryInterval
225+
)
226+
}
281227
}
282228

283229
/// Resets the user defaults.

0 commit comments

Comments
 (0)