Skip to content

Commit 438e613

Browse files
committed
[rc-swift] RemoteConfigValue
1 parent 0f9af07 commit 438e613

File tree

11 files changed

+80
-150
lines changed

11 files changed

+80
-150
lines changed

FirebaseRemoteConfig/Sources/FIRConfigValue.m

Lines changed: 0 additions & 91 deletions
This file was deleted.

FirebaseRemoteConfig/Sources/FIRRemoteConfig.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h"
2525
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
2626
#import "FirebaseRemoteConfig/Sources/RCNConfigRealtime.h"
27-
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
2827
#import "FirebaseRemoteConfig/Sources/RCNPersonalization.h"
2928

3029
#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"

FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
@class RCNConfigContent;
2323
@class FIROptions;
2424
@class RCNConfigSettings;
25+
@class FIRRemoteConfigValue;
2526
@protocol FIRAnalyticsInterop;
2627

2728
/// The Firebase Remote Config service default namespace, to be used if the API method does not
@@ -139,31 +140,6 @@ typedef void (^FIRRemoteConfigFetchAndActivateCompletion)(
139140
FIRRemoteConfigFetchAndActivateStatus status, NSError *_Nullable error)
140141
NS_SWIFT_UNAVAILABLE("Use Swift's closure syntax instead.");
141142

142-
#pragma mark - FIRRemoteConfigValue
143-
/// This class provides a wrapper for Remote Config parameter values, with methods to get parameter
144-
/// values as different data types.
145-
NS_SWIFT_NAME(RemoteConfigValue)
146-
@interface FIRRemoteConfigValue : NSObject <NSCopying>
147-
/// Gets the value as a string.
148-
@property(nonatomic, readonly, nonnull) NSString *stringValue;
149-
/// Gets the value as a number value.
150-
@property(nonatomic, readonly, nonnull) NSNumber *numberValue;
151-
/// Gets the value as a NSData object.
152-
@property(nonatomic, readonly, nonnull) NSData *dataValue;
153-
/// Gets the value as a boolean.
154-
@property(nonatomic, readonly) BOOL boolValue;
155-
/// Gets a foundation object (NSDictionary / NSArray) by parsing the value as JSON. This method uses
156-
/// NSJSONSerialization's JSONObjectWithData method with an options value of 0.
157-
@property(nonatomic, readonly, nullable) id JSONValue NS_SWIFT_NAME(jsonValue);
158-
/// Identifies the source of the fetched value.
159-
@property(nonatomic, readonly) FIRRemoteConfigSource source;
160-
161-
/// TODO: internal API for temporary bridging
162-
/// Designated initializer.
163-
- (instancetype _Nonnull)initWithData:(nullable NSData *)data
164-
source:(FIRRemoteConfigSource)source NS_DESIGNATED_INITIALIZER;
165-
@end
166-
167143
#pragma mark - FIRRemoteConfigSettings
168144
/// Firebase Remote Config settings.
169145
NS_SWIFT_NAME(RemoteConfigSettings)

FirebaseRemoteConfig/Sources/RCNConfigSettings.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"
2020

2121
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
22-
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
2322

2423
#import <GoogleUtilities/GULAppEnvironmentUtil.h>
2524
#import "FirebaseCore/Extension/FirebaseCoreInternal.h"

FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h

Lines changed: 0 additions & 27 deletions
This file was deleted.

FirebaseRemoteConfig/Sources/RCNPersonalization.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#import "FirebaseRemoteConfig/Sources/RCNPersonalization.h"
1818

19+
#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"
1920
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
20-
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
2121

2222
@implementation RCNPersonalization
2323

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright 2024 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
import FirebaseCore
16+
import Foundation
17+
18+
@objc(FIRRemoteConfigValue)
19+
public class RemoteConfigValue: NSObject, NSCopying {
20+
/// Data backing the config value.
21+
@objc public let dataValue: Data
22+
23+
/// Identifies the source of the fetched value.
24+
@objc public let source: RemoteConfigSource
25+
26+
/// Designated initializer
27+
@objc public init(data: Data, source: RemoteConfigSource) {
28+
dataValue = data
29+
self.source = source
30+
}
31+
32+
/// Gets the value as a string.
33+
@objc public var stringValue: String {
34+
if let string = String(data: dataValue, encoding: .utf8) {
35+
return string
36+
}
37+
return "" // Return empty string if data is not valid UTF-8
38+
}
39+
40+
/// Gets the value as a number value.
41+
@objc public var numberValue: NSNumber {
42+
return NSNumber(value: Double(stringValue) ?? 0)
43+
}
44+
45+
/// Gets the value as a boolean.
46+
@objc public var boolValue: Bool {
47+
return (stringValue as NSString).boolValue
48+
}
49+
50+
/// Gets a foundation object (NSDictionary / NSArray) by parsing the value as JSON.
51+
@objc(JSONValue) public var jsonValue: Any? {
52+
guard !dataValue.isEmpty else {
53+
return nil
54+
}
55+
do {
56+
let jsonObject = try JSONSerialization.jsonObject(with: dataValue, options: [])
57+
return jsonObject
58+
} catch {
59+
RCLog.debug("I-RCN000065", "Error parsing data as JSON.")
60+
return nil
61+
}
62+
}
63+
64+
/// Debug description showing the representations of all types.
65+
override public var debugDescription: String {
66+
let content = """
67+
Boolean: \(boolValue), String: \(stringValue), Number: \(numberValue), \
68+
JSON:\(String(describing: jsonValue)), Data: \(dataValue), Source: \(source.rawValue)
69+
"""
70+
return "<\(type(of: self)): \(Unmanaged.passUnretained(self).toOpaque()), \(content)>"
71+
}
72+
73+
/// Copy method.
74+
@objc public func copy(with zone: NSZone? = nil) -> Any {
75+
return RemoteConfigValue(data: dataValue, source: source)
76+
}
77+
}

FirebaseRemoteConfig/Tests/Unit/RCNConfigContentTest.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h"
2323
#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h"
2424
#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
25-
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
2625
#import "FirebaseRemoteConfig/Tests/Unit/RCNTestUtilities.h"
2726

2827
#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"

FirebaseRemoteConfig/Tests/Unit/RCNConfigExperimentTest.m

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#import "FirebaseRemoteConfig/Sources/Private/RCNConfigSettings.h"
2323
#import "FirebaseRemoteConfig/Sources/Public/FirebaseRemoteConfig/FIRRemoteConfig.h"
2424
#import "FirebaseRemoteConfig/Sources/RCNConfigDefines.h"
25-
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
2625
#import "FirebaseRemoteConfig/Tests/Unit/RCNTestUtilities.h"
2726

2827
#import "FirebaseABTesting/Sources/Private/FirebaseABTestingInternal.h"

FirebaseRemoteConfig/Tests/Unit/RCNConfigValueTest.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
#import <XCTest/XCTest.h>
1818

19-
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
19+
@import FirebaseRemoteConfig;
2020

2121
@interface FIRRemoteConfigValueTest : XCTestCase
2222
@end

0 commit comments

Comments
 (0)