Skip to content

Commit

Permalink
[Config] Consolidate getters and setters UserDefaultsManager.swift (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ncooke3 authored Nov 6, 2024
1 parent da081ec commit 8cf2e02
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 184 deletions.
108 changes: 54 additions & 54 deletions .github/workflows/remoteconfig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,60 +104,60 @@ jobs:
# path: .build
# key: ${{ steps.generate_cache_key.outputs.cache_key }}

spm:
# Don't run on private repo unless it is a PR.
if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'
needs: [spm-package-resolved]
strategy:
matrix:
include:
- os: macos-13
xcode: Xcode_15.2
target: iOS
test: spm
- os: macos-14
xcode: Xcode_15.4
target: iOS
test: spm
- os: macos-15
xcode: Xcode_16
target: iOS
test: spm
- os: macos-15
xcode: Xcode_16
target: tvOS
test: spm
- os: macos-15
xcode: Xcode_16
target: macOS
test: spm
- os: macos-15
xcode: Xcode_16
target: watchOS
test: spmbuildonly
- os: macos-15
xcode: Xcode_16
target: catalyst
test: spm
- os: macos-15
xcode: Xcode_16
target: visionOS
test: spm
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: actions/cache/restore@v4
with:
path: .build
key: ${{needs.spm-package-resolved.outputs.cache_key}}
- name: Xcode
run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app/Contents/Developer
- name: Initialize xcodebuild
run: scripts/setup_spm_tests.sh
- name: Unit Tests
run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigUnit ${{ matrix.target }} spm
- name: Fake Console tests
run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigFakeConsole ${{ matrix.target }} ${{ matrix.test }}
# spm:
# # Don't run on private repo unless it is a PR.
# if: (github.repository == 'Firebase/firebase-ios-sdk' && github.event_name == 'schedule') || github.event_name == 'pull_request'
# needs: [spm-package-resolved]
# strategy:
# matrix:
# include:
# - os: macos-13
# xcode: Xcode_15.2
# target: iOS
# test: spm
# - os: macos-14
# xcode: Xcode_15.4
# target: iOS
# test: spm
# - os: macos-15
# xcode: Xcode_16
# target: iOS
# test: spm
# - os: macos-15
# xcode: Xcode_16
# target: tvOS
# test: spm
# - os: macos-15
# xcode: Xcode_16
# target: macOS
# test: spm
# - os: macos-15
# xcode: Xcode_16
# target: watchOS
# test: spmbuildonly
# - os: macos-15
# xcode: Xcode_16
# target: catalyst
# test: spm
# - os: macos-15
# xcode: Xcode_16
# target: visionOS
# test: spm
# runs-on: ${{ matrix.os }}
# steps:
# - uses: actions/checkout@v4
# - uses: actions/cache/restore@v4
# with:
# path: .build
# key: ${{needs.spm-package-resolved.outputs.cache_key}}
# - name: Xcode
# run: sudo xcode-select -s /Applications/${{ matrix.xcode }}.app/Contents/Developer
# - name: Initialize xcodebuild
# run: scripts/setup_spm_tests.sh
# - name: Unit Tests
# run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigUnit ${{ matrix.target }} spm
# - name: Fake Console tests
# run: scripts/third_party/travis/retry.sh ./scripts/build.sh RemoteConfigFakeConsole ${{ matrix.target }} ${{ matrix.test }}

catalyst:
# Don't run on private repo unless it is a PR.
Expand Down
206 changes: 76 additions & 130 deletions FirebaseRemoteConfig/SwiftNew/UserDefaultsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,182 +102,128 @@ public class UserDefaultsManager: NSObject {

/// The last ETag received from the server.
@objc public var lastETag: String? {
return instanceUserDefaults[kRCNUserDefaultsKeyNamelastETag] as? String
}

/// Sets the last ETag received from the server.
///
/// - Parameter lastETag: The last ETag received from the server.
@objc public func setLastETag(_ lastETag: String?) {
if let lastETag = lastETag {
setInstanceUserDefaultsValue(lastETag, forKey: kRCNUserDefaultsKeyNamelastETag)
get { instanceUserDefaults[kRCNUserDefaultsKeyNamelastETag] as? String }
set {
if let lastETag = newValue {
setInstanceUserDefaultsValue(lastETag, forKey: kRCNUserDefaultsKeyNamelastETag)
}
}
}

/// The last fetched template version.
@objc public var lastFetchedTemplateVersion: String {
return instanceUserDefaults[ConfigConstants.fetchResponseKeyTemplateVersion] as? String ?? "0"
}

/// Sets the last fetched template version.
///
/// - Parameter templateVersion: The last fetched template version.
@objc public func setLastFetchedTemplateVersion(_ templateVersion: String) {
setInstanceUserDefaultsValue(
templateVersion,
forKey: ConfigConstants.fetchResponseKeyTemplateVersion
)
get { instanceUserDefaults[ConfigConstants.fetchResponseKeyTemplateVersion] as? String ?? "0" }
set {
setInstanceUserDefaultsValue(
newValue,
forKey: ConfigConstants.fetchResponseKeyTemplateVersion
)
}
}

/// The last active template version.
@objc public var lastActiveTemplateVersion: String {
return instanceUserDefaults[ConfigConstants.activeKeyTemplateVersion] as? String ?? "0"
}

/// Sets the last active template version.
///
/// - Parameter templateVersion: The last active template version.
@objc public func setLastActiveTemplateVersion(_ templateVersion: String) {
setInstanceUserDefaultsValue(templateVersion, forKey: ConfigConstants.activeKeyTemplateVersion)
get { instanceUserDefaults[ConfigConstants.activeKeyTemplateVersion] as? String ?? "0" }
set {
setInstanceUserDefaultsValue(newValue, forKey: ConfigConstants.activeKeyTemplateVersion)
}
}

/// The last ETag update time.
@objc public var lastETagUpdateTime: TimeInterval {
return instanceUserDefaults[kRCNUserDefaultsKeyNamelastETagUpdateTime] as? TimeInterval ?? 0
}

/// Sets the last ETag update time.
///
/// - Parameter lastETagUpdateTime: The last ETag update time.
@objc public func setLastETagUpdateTime(_ lastETagUpdateTime: TimeInterval) {
setInstanceUserDefaultsValue(
lastETagUpdateTime,
forKey: kRCNUserDefaultsKeyNamelastETagUpdateTime
)
get { instanceUserDefaults[kRCNUserDefaultsKeyNamelastETagUpdateTime] as? TimeInterval ?? 0 }
set {
setInstanceUserDefaultsValue(newValue, forKey: kRCNUserDefaultsKeyNamelastETagUpdateTime)
}
}

/// The last fetch time.
@objc public var lastFetchTime: TimeInterval {
return instanceUserDefaults[kRCNUserDefaultsKeyNameLastSuccessfulFetchTime] as? TimeInterval ??
0
}

/// Sets the last fetch time.
///
/// - Parameter lastFetchTime: The last fetch time.
@objc public func setLastFetchTime(_ lastFetchTime: TimeInterval) {
setInstanceUserDefaultsValue(
lastFetchTime,
forKey: kRCNUserDefaultsKeyNameLastSuccessfulFetchTime
)
get {
instanceUserDefaults[kRCNUserDefaultsKeyNameLastSuccessfulFetchTime] as? TimeInterval ?? 0
}
set {
setInstanceUserDefaultsValue(newValue, forKey: kRCNUserDefaultsKeyNameLastSuccessfulFetchTime)
}
}

/// The last fetch status.
@objc public var lastFetchStatus: String? {
return instanceUserDefaults[kRCNUserDefaultsKeyNamelastFetchStatus] as? String
}

/// Sets the last fetch status.
///
/// - Parameter lastFetchStatus: The last fetch status.
@objc public func setLastFetchStatus(_ lastFetchStatus: String?) {
if let lastFetchStatus = lastFetchStatus {
setInstanceUserDefaultsValue(lastFetchStatus, forKey: kRCNUserDefaultsKeyNamelastFetchStatus)
get { instanceUserDefaults[kRCNUserDefaultsKeyNamelastFetchStatus] as? String }
set {
if let lastFetchStatus = newValue {
setInstanceUserDefaultsValue(
lastFetchStatus,
forKey: kRCNUserDefaultsKeyNamelastFetchStatus
)
}
}
}

/// Whether the client is throttled with exponential backoff.
@objc public var isClientThrottledWithExponentialBackoff: Bool {
return instanceUserDefaults[kRCNUserDefaultsKeyNameIsClientThrottled] as? Bool ?? false
}

/// Sets whether the client is throttled with exponential backoff.
///
/// - Parameter isThrottledWithExponentialBackoff: Whether the client is throttled with
/// exponential backoff.
@objc public func setIsClientThrottledWithExponentialBackoff(_ isThrottledWithExponentialBackoff: Bool) {
setInstanceUserDefaultsValue(
isThrottledWithExponentialBackoff,
forKey: kRCNUserDefaultsKeyNameIsClientThrottled
)
get { instanceUserDefaults[kRCNUserDefaultsKeyNameIsClientThrottled] as? Bool ?? false }
set {
setInstanceUserDefaultsValue(
newValue,
forKey: kRCNUserDefaultsKeyNameIsClientThrottled
)
}
}

/// The throttle end time.
@objc public var throttleEndTime: TimeInterval {
return instanceUserDefaults[kRCNUserDefaultsKeyNameThrottleEndTime] as? TimeInterval ?? 0
}

/// Sets the throttle end time.
///
/// - Parameter throttleEndTime: The throttle end time.
@objc public func setThrottleEndTime(_ throttleEndTime: TimeInterval) {
setInstanceUserDefaultsValue(throttleEndTime, forKey: kRCNUserDefaultsKeyNameThrottleEndTime)
get { instanceUserDefaults[kRCNUserDefaultsKeyNameThrottleEndTime] as? TimeInterval ?? 0 }
set {
setInstanceUserDefaultsValue(newValue, forKey: kRCNUserDefaultsKeyNameThrottleEndTime)
}
}

/// The current throttling retry interval in seconds.
@objc public var currentThrottlingRetryIntervalSeconds: TimeInterval {
return instanceUserDefaults[
kRCNUserDefaultsKeyNameCurrentThrottlingRetryInterval
] as? TimeInterval ??
0
}

/// Sets the current throttling retry interval in seconds.
///
/// - Parameter throttlingRetryIntervalSeconds: The current throttling retry interval in seconds.
@objc public func setCurrentThrottlingRetryIntervalSeconds(_ throttlingRetryIntervalSeconds: TimeInterval) {
setInstanceUserDefaultsValue(
throttlingRetryIntervalSeconds,
forKey: kRCNUserDefaultsKeyNameCurrentThrottlingRetryInterval
)
get {
instanceUserDefaults[
kRCNUserDefaultsKeyNameCurrentThrottlingRetryInterval
] as? TimeInterval ?? 0
}
set {
setInstanceUserDefaultsValue(
newValue, forKey: kRCNUserDefaultsKeyNameCurrentThrottlingRetryInterval
)
}
}

/// The realtime retry count.
@objc public var realtimeRetryCount: Int {
return instanceUserDefaults[kRCNUserDefaultsKeyNameRealtimeRetryCount] as? Int ?? 0
}

/// Sets the realtime retry count.
///
/// - Parameter realtimeRetryCount: The realtime retry count.
@objc public func setRealtimeRetryCount(_ realtimeRetryCount: Int) {
setInstanceUserDefaultsValue(
realtimeRetryCount,
forKey: kRCNUserDefaultsKeyNameRealtimeRetryCount
)
get { instanceUserDefaults[kRCNUserDefaultsKeyNameRealtimeRetryCount] as? Int ?? 0 }
set { setInstanceUserDefaultsValue(newValue, forKey: kRCNUserDefaultsKeyNameRealtimeRetryCount)
}
}

/// The realtime throttle end time.
@objc public var realtimeThrottleEndTime: TimeInterval {
return instanceUserDefaults[kRCNUserDefaultsKeyNameRealtimeThrottleEndTime] as? TimeInterval ??
0
}

/// Sets the realtime throttle end time.
///
/// - Parameter throttleEndTime: The realtime throttle end time.
@objc public func setRealtimeThrottleEndTime(_ throttleEndTime: TimeInterval) {
setInstanceUserDefaultsValue(
throttleEndTime,
forKey: kRCNUserDefaultsKeyNameRealtimeThrottleEndTime
)
get {
instanceUserDefaults[kRCNUserDefaultsKeyNameRealtimeThrottleEndTime] as? TimeInterval ?? 0
}
set {
setInstanceUserDefaultsValue(
newValue, forKey: kRCNUserDefaultsKeyNameRealtimeThrottleEndTime
)
}
}

/// The current realtime throttling retry interval in seconds.
@objc public var currentRealtimeThrottlingRetryIntervalSeconds: TimeInterval {
return instanceUserDefaults[
kRCNUserDefaultsKeyNameCurrentRealtimeThrottlingRetryInterval
] as? TimeInterval ??
0
}

/// Sets the current realtime throttling retry interval in seconds.
///
/// - Parameter throttlingRetryIntervalSeconds: The current realtime throttling retry interval in
/// seconds.
@objc public func setCurrentRealtimeThrottlingRetryIntervalSeconds(_ throttlingRetryIntervalSeconds: TimeInterval) {
setInstanceUserDefaultsValue(throttlingRetryIntervalSeconds,
forKey: kRCNUserDefaultsKeyNameCurrentRealtimeThrottlingRetryInterval)
get {
instanceUserDefaults[
kRCNUserDefaultsKeyNameCurrentRealtimeThrottlingRetryInterval
] as? TimeInterval ?? 0
}
set {
setInstanceUserDefaultsValue(
newValue, forKey: kRCNUserDefaultsKeyNameCurrentRealtimeThrottlingRetryInterval
)
}
}

/// Resets the user defaults.
Expand Down

0 comments on commit 8cf2e02

Please sign in to comment.