Skip to content

Commit de73b8f

Browse files
Extend CustomSignalValue to include Double type
1 parent 6df9e32 commit de73b8f

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

FirebaseRemoteConfig/Swift/CustomSignals.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ import Foundation
1717
@_exported import FirebaseRemoteConfigInternal
1818
#endif // SWIFT_PACKAGE
1919

20-
// TODO: Document.
20+
/// Represents a value associated with a key in a custom signal, restricted to the allowed data
21+
/// types : String, Int, Double.
2122
public struct CustomSignalValue {
2223
private enum Kind {
2324
case string(String)
2425
case integer(Int)
26+
case double(Double)
2527
}
2628

2729
private let kind: Kind
@@ -44,12 +46,21 @@ public struct CustomSignalValue {
4446
Self(kind: .integer(integer))
4547
}
4648

49+
/// Returns an floating-point backed custom signal.
50+
/// - Parameter double: The given floating-point value to back the custom signal with.
51+
/// - Returns: An floating-point backed custom signal
52+
public static func double(_ double: Double) -> Self {
53+
Self(kind: .double(double))
54+
}
55+
4756
fileprivate func toNSObject() -> NSObject {
4857
switch kind {
4958
case let .string(string):
5059
return string as NSString
5160
case let .integer(int):
5261
return int as NSNumber
62+
case let .double(double):
63+
return double as NSNumber
5364
}
5465
}
5566
}
@@ -66,6 +77,12 @@ extension CustomSignalValue: ExpressibleByIntegerLiteral {
6677
}
6778
}
6879

80+
extension CustomSignalValue: ExpressibleByFloatLiteral {
81+
public init(floatLiteral value: Double) {
82+
self = .double(value)
83+
}
84+
}
85+
6986
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
7087
public extension RemoteConfig {
7188
/// Sets custom signals for this Remote Config instance.

FirebaseRemoteConfig/Tests/Swift/SwiftAPI/FirebaseRemoteConfigSwift_APIBuildTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ final class FirebaseRemoteConfig_APIBuildTests: XCTestCase {
231231
"signal_3": 5,
232232
"signal_4": "enable_feature",
233233
"signal_5": "enable_feature_\("secret")",
234-
"signal_6": nil, // Used to delete the custom signal for a given key.
234+
"signal_6": .double(3.14),
235+
"signal_7": 3.14159,
236+
"signal_8": nil, // Used to delete the custom signal for a given key.
235237
]
236238
try await config.setCustomSignals(signals)
237239
}

0 commit comments

Comments
 (0)