Skip to content

Commit

Permalink
[rc-swift] RemoteConfigValue
Browse files Browse the repository at this point in the history
  • Loading branch information
paulb777 committed Dec 11, 2024
1 parent 0f9af07 commit 438e613
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 150 deletions.
91 changes: 0 additions & 91 deletions FirebaseRemoteConfig/Sources/FIRConfigValue.m

This file was deleted.

1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Sources/FIRRemoteConfig.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <NSCopying>
/// 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)
Expand Down
1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Sources/RCNConfigSettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#import "FirebaseRemoteConfig/FirebaseRemoteConfig-Swift.h"

#import "FirebaseRemoteConfig/Sources/RCNConfigConstants.h"
#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"

#import <GoogleUtilities/GULAppEnvironmentUtil.h>
#import "FirebaseCore/Extension/FirebaseCoreInternal.h"
Expand Down
27 changes: 0 additions & 27 deletions FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h

This file was deleted.

2 changes: 1 addition & 1 deletion FirebaseRemoteConfig/Sources/RCNPersonalization.m
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
77 changes: 77 additions & 0 deletions FirebaseRemoteConfig/SwiftNew/RemoteConfigValue.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Tests/Unit/RCNConfigContentTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Tests/Unit/RCNConfigExperimentTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion FirebaseRemoteConfig/Tests/Unit/RCNConfigValueTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

#import <XCTest/XCTest.h>

#import "FirebaseRemoteConfig/Sources/RCNConfigValue_Internal.h"
@import FirebaseRemoteConfig;

@interface FIRRemoteConfigValueTest : XCTestCase
@end
Expand Down
1 change: 0 additions & 1 deletion FirebaseRemoteConfig/Tests/Unit/RCNPersonalizationTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 438e613

Please sign in to comment.