From 438e61359cfcdf65129bcd0f523516fdb0e78b06 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 11 Dec 2024 14:45:42 -0800 Subject: [PATCH 1/6] [rc-swift] RemoteConfigValue --- FirebaseRemoteConfig/Sources/FIRConfigValue.m | 91 ------------------- .../Sources/FIRRemoteConfig.m | 1 - .../FirebaseRemoteConfig/FIRRemoteConfig.h | 26 +----- .../Sources/RCNConfigSettings.m | 1 - .../Sources/RCNConfigValue_Internal.h | 27 ------ .../Sources/RCNPersonalization.m | 2 +- .../SwiftNew/RemoteConfigValue.swift | 77 ++++++++++++++++ .../Tests/Unit/RCNConfigContentTest.m | 1 - .../Tests/Unit/RCNConfigExperimentTest.m | 1 - .../Tests/Unit/RCNConfigValueTest.m | 2 +- .../Tests/Unit/RCNPersonalizationTest.m | 1 - 11 files changed, 80 insertions(+), 150 deletions(-) delete mode 100644 FirebaseRemoteConfig/Sources/FIRConfigValue.m delete mode 100644 FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h create mode 100644 FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift diff --git a/FirebaseRemoteConfig/Sources/FIRConfigValue.m b/FirebaseRemoteConfig/Sources/FIRConfigValue.m deleted file mode 100644 index 96e03aa7044..00000000000 --- a/FirebaseRemoteConfig/Sources/FIRConfigValue.m +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Copyright 2019 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h" - -#import "FirebaseCore/Extension/FirebaseCoreInternal.h" -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" - -@implementation FIRRemoteConfigValue { - /// Data backing the config value. - NSData *_data; - FIRRemoteConfigSource _source; -} - -/// Designated initializer -- (instancetype)initWithData:(nullable NSData *)data source:(FIRRemoteConfigSource)source { - self = [super init]; - if (self) { - _data = [data copy]; - _source = source; - } - return self; -} - -/// Superclass's designated initializer -- (instancetype)init { - return [self initWithData:nil source:FIRRemoteConfigSourceStatic]; -} - -/// The string is a UTF-8 representation of NSData. -- (nonnull NSString *)stringValue { - return [[NSString alloc] initWithData:_data encoding:NSUTF8StringEncoding] ?: @""; -} - -/// Number representation of a UTF-8 string. -- (NSNumber *)numberValue { - return [NSNumber numberWithDouble:self.stringValue.doubleValue]; -} - -/// Internal representation of the FIRRemoteConfigValue as a NSData object. -- (NSData *)dataValue { - return _data; -} - -/// Boolean representation of a UTF-8 string. -- (BOOL)boolValue { - return self.stringValue.boolValue; -} - -/// Returns a foundation object (NSDictionary / NSArray) representation for JSON data. -- (id)JSONValue { - NSError *error; - if (!_data) { - return nil; - } - id JSONObject = [NSJSONSerialization JSONObjectWithData:_data options:kNilOptions error:&error]; - if (error) { - FIRLogDebug(kFIRLoggerRemoteConfig, @"I-RCN000065", @"Error parsing data as JSON."); - return nil; - } - return JSONObject; -} - -/// Debug description showing the representations of all types. -- (NSString *)debugDescription { - NSString *content = [NSString - stringWithFormat:@"Boolean: %d, String: %@, Number: %@, JSON:%@, Data: %@, Source: %zd", - self.boolValue, self.stringValue, self.numberValue, self.JSONValue, _data, - (long)self.source]; - return [NSString stringWithFormat:@"<%@: %p, %@>", [self class], self, content]; -} - -/// Copy method. -- (id)copyWithZone:(NSZone *)zone { - FIRRemoteConfigValue *value = [[[self class] allocWithZone:zone] initWithData:_data]; - return value; -} -@end diff --git a/FirebaseRemoteConfig/Sources/FIRRemoteConfig.m b/FirebaseRemoteConfig/Sources/FIRRemoteConfig.m index ca38f0f8841..958fbb4f9f9 100644 --- a/FirebaseRemoteConfig/Sources/FIRRemoteConfig.m +++ b/FirebaseRemoteConfig/Sources/FIRRemoteConfig.m @@ -24,7 +24,6 @@ #import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h" #import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h" #import "FirebaseRemoteConfig/Sources/RCNConfigRealtime.h" -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" #import "FirebaseRemoteConfig/Sources/RCNPersonalization.h" #import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h" diff --git a/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h b/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h index c5df0dfd9fa..459b898b76f 100644 --- a/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h +++ b/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h @@ -22,6 +22,7 @@ @class RCNConfigContent; @class FIROptions; @class RCNConfigSettings; +@class FIRRemoteConfigValue; @protocol FIRAnalyticsInterop; /// The Firebase Remote Config service default namespace, to be used if the API method does not @@ -139,31 +140,6 @@ typedef void (^FIRRemoteConfigFetchAndActivateCompletion)( FIRRemoteConfigFetchAndActivateStatus status, NSError *_Nullable error) NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead."); -#pragma mark - FIRRemoteConfigValue -/// This class provides a wrapper for Remote Config parameter values, with methods to get parameter -/// values as different data types. -NS_SWIFT_NAME(RemoteConfigValue) -@interface FIRRemoteConfigValue : NSObject -/// Gets the value as a string. -@property(nonatomic, readonly, nonnull) NSString *stringValue; -/// Gets the value as a number value. -@property(nonatomic, readonly, nonnull) NSNumber *numberValue; -/// Gets the value as a NSData object. -@property(nonatomic, readonly, nonnull) NSData *dataValue; -/// Gets the value as a boolean. -@property(nonatomic, readonly) BOOL boolValue; -/// Gets a foundation object (NSDictionary / NSArray) by parsing the value as JSON. This method uses -/// NSJSONSerialization's JSONObjectWithData method with an options value of 0. -@property(nonatomic, readonly, nullable) id JSONValue NS_SWIFT_NAME(jsonValue); -/// Identifies the source of the fetched value. -@property(nonatomic, readonly) FIRRemoteConfigSource source; - -/// TODO: internal API for temporary bridging -/// Designated initializer. -- (instancetype _Nonnull)initWithData:(nullable NSData *)data - source:(FIRRemoteConfigSource)source NS_DESIGNATED_INITIALIZER; -@end - #pragma mark - FIRRemoteConfigSettings /// Firebase Remote Config settings. NS_SWIFT_NAME(RemoteConfigSettings) diff --git a/FirebaseRemoteConfig/Sources/RCNConfigSettings.m b/FirebaseRemoteConfig/Sources/RCNConfigSettings.m index 3bc86977fdb..19d6e6ca9ea 100644 --- a/FirebaseRemoteConfig/Sources/RCNConfigSettings.m +++ b/FirebaseRemoteConfig/Sources/RCNConfigSettings.m @@ -19,7 +19,6 @@ #import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h" #import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h" -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" #import #import "FirebaseCore/Extension/FirebaseCoreInternal.h" diff --git a/FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h b/FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h deleted file mode 100644 index c5a7d21e002..00000000000 --- a/FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright 2019 Google - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h" - -NS_ASSUME_NONNULL_BEGIN -@interface FIRRemoteConfigValue () -@property(nonatomic, readwrite, assign) FIRRemoteConfigSource source; - -/// Designated initializer. -- (instancetype)initWithData:(nullable NSData *)data - source:(FIRRemoteConfigSource)source NS_DESIGNATED_INITIALIZER; -@end -NS_ASSUME_NONNULL_END diff --git a/FirebaseRemoteConfig/Sources/RCNPersonalization.m b/FirebaseRemoteConfig/Sources/RCNPersonalization.m index 0bcb41193bf..2c41fc30f25 100644 --- a/FirebaseRemoteConfig/Sources/RCNPersonalization.m +++ b/FirebaseRemoteConfig/Sources/RCNPersonalization.m @@ -16,8 +16,8 @@ #import "FirebaseRemoteConfig/Sources/RCNPersonalization.h" +#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h" #import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h" -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" @implementation RCNPersonalization diff --git a/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift b/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift new file mode 100644 index 00000000000..609635db26a --- /dev/null +++ b/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift @@ -0,0 +1,77 @@ +// Copyright 2024 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import FirebaseCore +import Foundation + +@objc(FIRRemoteConfigValue) +public class RemoteConfigValue: NSObject, NSCopying { + /// Data backing the config value. + @objc public let dataValue: Data + + /// Identifies the source of the fetched value. + @objc public let source: RemoteConfigSource + + /// Designated initializer + @objc public init(data: Data, source: RemoteConfigSource) { + dataValue = data + self.source = source + } + + /// Gets the value as a string. + @objc public var stringValue: String { + if let string = String(data: dataValue, encoding: .utf8) { + return string + } + return "" // Return empty string if data is not valid UTF-8 + } + + /// Gets the value as a number value. + @objc public var numberValue: NSNumber { + return NSNumber(value: Double(stringValue) ?? 0) + } + + /// Gets the value as a boolean. + @objc public var boolValue: Bool { + return (stringValue as NSString).boolValue + } + + /// Gets a foundation object (NSDictionary / NSArray) by parsing the value as JSON. + @objc(JSONValue) public var jsonValue: Any? { + guard !dataValue.isEmpty else { + return nil + } + do { + let jsonObject = try JSONSerialization.jsonObject(with: dataValue, options: []) + return jsonObject + } catch { + RCLog.debug("I-RCN000065", "Error parsing data as JSON.") + return nil + } + } + + /// Debug description showing the representations of all types. + override public var debugDescription: String { + let content = """ + Boolean: \(boolValue), String: \(stringValue), Number: \(numberValue), \ + JSON:\(String(describing: jsonValue)), Data: \(dataValue), Source: \(source.rawValue) + """ + return "<\(type(of: self)): \(Unmanaged.passUnretained(self).toOpaque()), \(content)>" + } + + /// Copy method. + @objc public func copy(with zone: NSZone? = nil) -> Any { + return RemoteConfigValue(data: dataValue, source: source) + } +} diff --git a/FirebaseRemoteConfig/Tests/Unit/RCNConfigContentTest.m b/FirebaseRemoteConfig/Tests/Unit/RCNConfigContentTest.m index 01661b12a44..ed68786784d 100644 --- a/FirebaseRemoteConfig/Tests/Unit/RCNConfigContentTest.m +++ b/FirebaseRemoteConfig/Tests/Unit/RCNConfigContentTest.m @@ -22,7 +22,6 @@ #import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h" #import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h" #import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h" -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" #import "FirebaseRemoteConfig/Tests/Unit/RCNTestUtilities.h" #import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h" diff --git a/FirebaseRemoteConfig/Tests/Unit/RCNConfigExperimentTest.m b/FirebaseRemoteConfig/Tests/Unit/RCNConfigExperimentTest.m index 2de42eb01cd..0c5de6eb45c 100644 --- a/FirebaseRemoteConfig/Tests/Unit/RCNConfigExperimentTest.m +++ b/FirebaseRemoteConfig/Tests/Unit/RCNConfigExperimentTest.m @@ -22,7 +22,6 @@ #import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h" #import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h" #import "FirebaseRemoteConfig/Sources/RCNConfigDefines.h" -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" #import "FirebaseRemoteConfig/Tests/Unit/RCNTestUtilities.h" #import "FirebaseABTesting/Sources/Private/FirebaseABTestingInternal.h" diff --git a/FirebaseRemoteConfig/Tests/Unit/RCNConfigValueTest.m b/FirebaseRemoteConfig/Tests/Unit/RCNConfigValueTest.m index a12af9c13ee..912abe2b698 100644 --- a/FirebaseRemoteConfig/Tests/Unit/RCNConfigValueTest.m +++ b/FirebaseRemoteConfig/Tests/Unit/RCNConfigValueTest.m @@ -16,7 +16,7 @@ #import -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" +@import FirebaseRemoteConfig; @interface FIRRemoteConfigValueTest : XCTestCase @end diff --git a/FirebaseRemoteConfig/Tests/Unit/RCNPersonalizationTest.m b/FirebaseRemoteConfig/Tests/Unit/RCNPersonalizationTest.m index 282f3f9193d..5219da1c5c5 100644 --- a/FirebaseRemoteConfig/Tests/Unit/RCNPersonalizationTest.m +++ b/FirebaseRemoteConfig/Tests/Unit/RCNPersonalizationTest.m @@ -23,7 +23,6 @@ // #import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h" #import "FirebaseRemoteConfig/Sources/Private/RCNConfigFetch.h" #import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h" -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" #import "FirebaseRemoteConfig/Sources/RCNPersonalization.h" #import "FirebaseRemoteConfig/Tests/Unit/RCNTestUtilities.h" #import "Interop/Analytics/Public/FIRAnalyticsInterop.h" From b74d065c4bec4a1277bfaae5e014e575d845920d Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 11 Dec 2024 15:15:52 -0800 Subject: [PATCH 2/6] CI fixes --- .../Sources/Configurations/FPRRemoteConfigFlags.m | 2 ++ .../Unit/Configurations/FPRFakeRemoteConfig.h | 3 ++- .../Unit/Configurations/FPRRemoteConfigFlagsTest.m | 14 +++++++------- .../Tests/Unit/Timer/FIRTraceTest.m | 2 +- .../SwiftNew/RemoteConfigValue.swift | 4 ++-- .../FirebaseRemoteConfigSwift_APIBuildTests.swift | 4 ++-- 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.m b/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.m index 86f1280b812..96e9d616d22 100644 --- a/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.m +++ b/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.m @@ -23,6 +23,8 @@ #import "FirebaseCore/Extension/FirebaseCoreInternal.h" +@import FirebaseRemoteConfig; + #define ONE_DAY_SECONDS 24 * 60 * 60 static NSDate *FPRAppStartTime = nil; diff --git a/FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h b/FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h index 025ae7c9b09..59228178b85 100644 --- a/FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h +++ b/FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h @@ -15,7 +15,8 @@ #import #import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h" -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" + +@import FirebaseRemoteConfig; NS_ASSUME_NONNULL_BEGIN diff --git a/FirebasePerformance/Tests/Unit/Configurations/FPRRemoteConfigFlagsTest.m b/FirebasePerformance/Tests/Unit/Configurations/FPRRemoteConfigFlagsTest.m index e8fefb09864..79af610c17f 100644 --- a/FirebasePerformance/Tests/Unit/Configurations/FPRRemoteConfigFlagsTest.m +++ b/FirebasePerformance/Tests/Unit/Configurations/FPRRemoteConfigFlagsTest.m @@ -65,7 +65,7 @@ - (void)testCacheResetAfterEverySuccessfulFetch { forKey:@"fpr_vc_session_sampling_rate"]; // Trigger the RC config fetch - remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess; + remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData; remoteConfig.lastFetchTime = nil; configFlags.appStartConfigFetchDelayInSeconds = 0.0; [configFlags update]; @@ -92,7 +92,7 @@ - (void)testCacheResetAfterEverySuccessfulFetch { forKey:@"fpr_vc_session_sampling_rate"]; // Retrigger the RC config fetch - remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess; + remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData; remoteConfig.lastFetchTime = nil; [configFlags update]; @@ -112,7 +112,7 @@ - (void)testConfigUpdate { FPRRemoteConfigFlags *configFlags = [[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig]; - remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess; + remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData; configFlags.appStartConfigFetchDelayInSeconds = 0.0; [configFlags update]; XCTAssertNotNil(configFlags.lastFetchedTime); @@ -179,7 +179,7 @@ - (void)testConfigUpdateDoesNotHappenImmediately { FPRRemoteConfigFlags *configFlags = [[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig]; - remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess; + remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData; configFlags.appStartConfigFetchDelayInSeconds = 0.0; [configFlags update]; XCTAssertNotNil(configFlags.lastFetchedTime); @@ -203,7 +203,7 @@ - (void)testConfigUpdateHappensIfInitialFetchHasNotHappened { FPRRemoteConfigFlags *configFlags = [[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig]; - remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess; + remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData; configFlags.appStartConfigFetchDelayInSeconds = 0.0; [configFlags update]; XCTAssertNotNil(configFlags.lastFetchedTime); @@ -224,7 +224,7 @@ - (void)testConfigFetchHappensDoesNotHappenImmediately { [[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig]; // Setting the status to success. Calling update on the config flags should trigger updation of // fetch time. Fetch would trigger activation. - remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess; + remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData; NSDate *lastActivatedTime = configFlags.lastFetchedTime; [configFlags update]; XCTAssert([configFlags.lastFetchedTime timeIntervalSinceDate:lastActivatedTime] == 0); @@ -240,7 +240,7 @@ - (void)testConfigFetchHappensAfterDelay { [[FPRRemoteConfigFlags alloc] initWithRemoteConfig:(FIRRemoteConfig *)remoteConfig]; configFlags.appStartConfigFetchDelayInSeconds = 0.0; - remoteConfig.fetchStatus = FIRRemoteConfigFetchStatusSuccess; + remoteConfig.fetchStatus = FIRRemoteConfigFetchAndActivateStatusSuccessUsingPreFetchedData; XCTestExpectation *expectation = [self expectationWithDescription:@"Dummy expectation to wait for the fetch delay."]; dispatch_after( diff --git a/FirebasePerformance/Tests/Unit/Timer/FIRTraceTest.m b/FirebasePerformance/Tests/Unit/Timer/FIRTraceTest.m index 39a389fdb3b..32b4753766d 100644 --- a/FirebasePerformance/Tests/Unit/Timer/FIRTraceTest.m +++ b/FirebasePerformance/Tests/Unit/Timer/FIRTraceTest.m @@ -32,7 +32,7 @@ #import "FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h" #import "FirebasePerformance/Tests/Unit/FPRTestCase.h" -#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h" +@import FirebaseRemoteConfig; #import diff --git a/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift b/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift index 609635db26a..e062c21d36d 100644 --- a/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift +++ b/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift @@ -20,10 +20,10 @@ public class RemoteConfigValue: NSObject, NSCopying { /// Data backing the config value. @objc public let dataValue: Data - /// Identifies the source of the fetched value. + /// Identifies the source of the fetched value. Only for Firebase internal use. @objc public let source: RemoteConfigSource - /// Designated initializer + /// Designated initializer. Only for Firebase internal use. @objc public init(data: Data, source: RemoteConfigSource) { dataValue = data self.source = source diff --git a/FirebaseRemoteConfig/Tests/Swift/SwiftAPI/FirebaseRemoteConfigSwift_APIBuildTests.swift b/FirebaseRemoteConfig/Tests/Swift/SwiftAPI/FirebaseRemoteConfigSwift_APIBuildTests.swift index 56fc336908e..e390e61c4c2 100644 --- a/FirebaseRemoteConfig/Tests/Swift/SwiftAPI/FirebaseRemoteConfigSwift_APIBuildTests.swift +++ b/FirebaseRemoteConfig/Tests/Swift/SwiftAPI/FirebaseRemoteConfigSwift_APIBuildTests.swift @@ -85,8 +85,8 @@ final class FirebaseRemoteConfig_APIBuildTests: XCTestCase { _ = FirebaseRemoteConfig.RemoteConfigUpdateError.messageInvalid _ = FirebaseRemoteConfig.RemoteConfigUpdateError.unavailable - // TODO(ncooke3): This should probably not be initializable. - let value = FirebaseRemoteConfig.RemoteConfigValue() + // This is only initializable for internal clients - fire-perf. + let value = FirebaseRemoteConfig.RemoteConfigValue(data: Data(), source: .default) let _: String? = value.stringValue // TODO(ncooke3): Returns an Objective-C reference type. let _: NSNumber = value.numberValue From 7fa6b955dbf6a5647fc2a214478f28556ef6425e Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 11 Dec 2024 15:47:36 -0800 Subject: [PATCH 3/6] fixes --- .../Configurations/FPRRemoteConfigFlags+Private.h | 2 +- .../Tests/Unit/Configurations/FPRFakeRemoteConfig.h | 4 +++- .../Unit/Configurations/FPRRemoteConfigFlagsTest.m | 2 ++ .../Sources/Private/FIRRemoteConfig_Private.h | 12 ------------ .../Public/FirebaseRemoteConfig/FIRRemoteConfig.h | 13 +++++++++++++ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h b/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h index 9279d457f07..699ccd3bed3 100644 --- a/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h +++ b/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h @@ -14,7 +14,7 @@ #import "FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags.h" -#import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h" +@import FirebaseRemoteConfig; NS_ASSUME_NONNULL_BEGIN diff --git a/FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h b/FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h index 59228178b85..fa8b1103bd8 100644 --- a/FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h +++ b/FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h @@ -14,7 +14,7 @@ #import -#import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h" +@import FirebaseRemoteConfig; @import FirebaseRemoteConfig; @@ -38,6 +38,8 @@ NS_ASSUME_NONNULL_BEGIN /** @brief Different configurations values that needs to be stored and returned. */ @property(nonatomic) NSMutableDictionary *configValues; +- (instancetype)init; + /** * Fake fetch call for fetching configs. Calling this method will just call the completionHandler. * diff --git a/FirebasePerformance/Tests/Unit/Configurations/FPRRemoteConfigFlagsTest.m b/FirebasePerformance/Tests/Unit/Configurations/FPRRemoteConfigFlagsTest.m index 79af610c17f..101f8a8ab9d 100644 --- a/FirebasePerformance/Tests/Unit/Configurations/FPRRemoteConfigFlagsTest.m +++ b/FirebasePerformance/Tests/Unit/Configurations/FPRRemoteConfigFlagsTest.m @@ -22,6 +22,8 @@ #import "FirebasePerformance/Tests/Unit/Configurations/FPRFakeRemoteConfig.h" +@import FirebaseRemoteConfig; + static NSInteger const kLogSource = 462; // LogRequest_LogSource_Fireperf @interface FPRRemoteConfigFlagsTest : XCTestCase diff --git a/FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h b/FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h index ae958f973a5..8a2050aad25 100644 --- a/FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h +++ b/FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h @@ -49,18 +49,6 @@ NS_ASSUME_NONNULL_BEGIN + (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace NS_SWIFT_NAME(remoteConfig(FIRNamespace:)); -/// Returns the FIRRemoteConfig instance for your namespace and for the default 3P developer's app. -/// This singleton object contains the complete set of Remote Config parameter values available to -/// the app, including the Active Config and Default Config. This object also caches values fetched -/// from the Remote Config Server until they are copied to the Active Config by calling -/// activateFetched. When you fetch values from the Remote Config Server using the default Firebase -/// namespace service, you should use this class method to create a shared instance of the -/// FIRRemoteConfig object to ensure that your app will function properly with the Remote Config -/// Server and the Firebase service. -+ (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace - app:(FIRApp *)app - NS_SWIFT_NAME(remoteConfig(FIRNamespace:app:)); - /// Register RolloutsStateSubcriber to FIRRemoteConfig instance - (void)addRemoteConfigInteropSubscriber:(id _Nonnull)subscriber; diff --git a/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h b/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h index 459b898b76f..5513f41bb62 100644 --- a/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h +++ b/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h @@ -354,5 +354,18 @@ typedef void (^FIRRemoteConfigUpdateCompletion)(FIRRemoteConfigUpdate *_Nullable userDefaults:(nullable NSUserDefaults *)userDefaults analytics:(nullable id)analytics; +/// Firebase INTERNAL use only! +/// Returns the FIRRemoteConfig instance for your namespace and for the default 3P developer's app. +/// This singleton object contains the complete set of Remote Config parameter values available to +/// the app, including the Active Config and Default Config. This object also caches values fetched +/// from the Remote Config Server until they are copied to the Active Config by calling +/// activateFetched. When you fetch values from the Remote Config Server using the default Firebase +/// namespace service, you should use this class method to create a shared instance of the +/// FIRRemoteConfig object to ensure that your app will function properly with the Remote Config +/// Server and the Firebase service. ++ (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace + app:(FIRApp *)app + NS_SWIFT_NAME(remoteConfig(FIRNamespace:app:)); + @end NS_ASSUME_NONNULL_END From 5583b3e13011fae7f3d6604d92548e773d0c68d1 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Wed, 11 Dec 2024 16:02:06 -0800 Subject: [PATCH 4/6] no Xcode 15 --- .github/workflows/performance.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/performance.yml b/.github/workflows/performance.yml index 5a4c08e98a7..70426acaf89 100644 --- a/.github/workflows/performance.yml +++ b/.github/workflows/performance.yml @@ -55,8 +55,6 @@ jobs: matrix: target: [ios, tvos] build-env: - - os: macos-14 - xcode: Xcode_15.2 - os: macos-15 xcode: Xcode_16.1 runs-on: ${{ matrix.build-env.os }} From e68fcc9476b8e8b9c212292839732bf1e4553c0e Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Thu, 12 Dec 2024 10:38:33 -0800 Subject: [PATCH 5/6] review --- .../Configurations/FPRRemoteConfigFlags+Private.h | 13 +++++++++++++ .../Public/FirebaseRemoteConfig/FIRRemoteConfig.h | 13 ------------- .../SwiftNew/RemoteConfigValue.swift | 6 ++++-- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h b/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h index 699ccd3bed3..bdf5a521e96 100644 --- a/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h +++ b/FirebasePerformance/Sources/Configurations/FPRRemoteConfigFlags+Private.h @@ -18,6 +18,19 @@ NS_ASSUME_NONNULL_BEGIN +@interface FIRRemoteConfig () ++ (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace + app:(FIRApp *)app; +@end + +@interface FIRRemoteConfigValue () +@property(nonatomic, readwrite, assign) FIRRemoteConfigSource source; + +/// Designated initializer. +- (instancetype)initWithData:(nullable NSData *)data + source:(FIRRemoteConfigSource)source NS_DESIGNATED_INITIALIZER; +@end + @class GULUserDefaults; static NSString *const kFPRConfigPrefix = @"com.fireperf"; diff --git a/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h b/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h index 5513f41bb62..459b898b76f 100644 --- a/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h +++ b/FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h @@ -354,18 +354,5 @@ typedef void (^FIRRemoteConfigUpdateCompletion)(FIRRemoteConfigUpdate *_Nullable userDefaults:(nullable NSUserDefaults *)userDefaults analytics:(nullable id)analytics; -/// Firebase INTERNAL use only! -/// Returns the FIRRemoteConfig instance for your namespace and for the default 3P developer's app. -/// This singleton object contains the complete set of Remote Config parameter values available to -/// the app, including the Active Config and Default Config. This object also caches values fetched -/// from the Remote Config Server until they are copied to the Active Config by calling -/// activateFetched. When you fetch values from the Remote Config Server using the default Firebase -/// namespace service, you should use this class method to create a shared instance of the -/// FIRRemoteConfig object to ensure that your app will function properly with the Remote Config -/// Server and the Firebase service. -+ (FIRRemoteConfig *)remoteConfigWithFIRNamespace:(NSString *)remoteConfigNamespace - app:(FIRApp *)app - NS_SWIFT_NAME(remoteConfig(FIRNamespace:app:)); - @end NS_ASSUME_NONNULL_END diff --git a/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift b/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift index e062c21d36d..3928c19a738 100644 --- a/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift +++ b/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift @@ -15,6 +15,8 @@ import FirebaseCore import Foundation +// TODO: Some objc's and public's should be removed. + @objc(FIRRemoteConfigValue) public class RemoteConfigValue: NSObject, NSCopying { /// Data backing the config value. @@ -24,8 +26,8 @@ public class RemoteConfigValue: NSObject, NSCopying { @objc public let source: RemoteConfigSource /// Designated initializer. Only for Firebase internal use. - @objc public init(data: Data, source: RemoteConfigSource) { - dataValue = data + @objc public init(data: Data?, source: RemoteConfigSource) { + dataValue = data ?? Data() self.source = source } From 6e6fd9b838de3ce1df89cd3ee086515b958cbe73 Mon Sep 17 00:00:00 2001 From: Paul Beusterien Date: Thu, 12 Dec 2024 10:52:02 -0800 Subject: [PATCH 6/6] review 2 --- FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift | 3 --- 1 file changed, 3 deletions(-) diff --git a/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift b/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift index 3928c19a738..d512a964bb3 100644 --- a/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift +++ b/FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift @@ -51,9 +51,6 @@ public class RemoteConfigValue: NSObject, NSCopying { /// Gets a foundation object (NSDictionary / NSArray) by parsing the value as JSON. @objc(JSONValue) public var jsonValue: Any? { - guard !dataValue.isEmpty else { - return nil - } do { let jsonObject = try JSONSerialization.jsonObject(with: dataValue, options: []) return jsonObject