From 877eb544748625db966687eb0e159bc99552a11f Mon Sep 17 00:00:00 2001 From: Nick Cooke Date: Wed, 6 Nov 2024 12:13:54 -0500 Subject: [PATCH 1/2] [Config] Consolidate getters and setters UserDefaultsManager.swift --- .../SwiftNew/UserDefaultsManager.swift | 206 +++++++----------- 1 file changed, 76 insertions(+), 130 deletions(-) diff --git a/FirebaseRemoteConfig/SwiftNew/UserDefaultsManager.swift b/FirebaseRemoteConfig/SwiftNew/UserDefaultsManager.swift index 2cdab034051..8287b5c87c6 100644 --- a/FirebaseRemoteConfig/SwiftNew/UserDefaultsManager.swift +++ b/FirebaseRemoteConfig/SwiftNew/UserDefaultsManager.swift @@ -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. From 764d97495dc7c294f46dc148a2fdb1f2ca8b54f1 Mon Sep 17 00:00:00 2001 From: Nick Cooke <36927374+ncooke3@users.noreply.github.com> Date: Wed, 6 Nov 2024 13:55:14 -0500 Subject: [PATCH 2/2] Fix workflow --- .github/workflows/remoteconfig.yml | 108 ++++++++++++++--------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/.github/workflows/remoteconfig.yml b/.github/workflows/remoteconfig.yml index fb812ace32e..31a396f8682 100644 --- a/.github/workflows/remoteconfig.yml +++ b/.github/workflows/remoteconfig.yml @@ -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.