Skip to content

Commit

Permalink
fix: re-add deprecated generic variable() and variableValue() methods (
Browse files Browse the repository at this point in the history
…#191)

* fix: re-add deprecated generic variable() and variableValue() methods

Signed-off-by: Jonathan Norris <[email protected]>

* fix: change test setup

Signed-off-by: Jonathan Norris <[email protected]>

---------

Signed-off-by: Jonathan Norris <[email protected]>
  • Loading branch information
jonathannorris authored Mar 28, 2024
1 parent 5afe6b0 commit 1ea7fc4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions DevCycle/DevCycleClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ public class DevCycleClient {
public func variableValue(key: String, defaultValue: NSDictionary) -> NSDictionary {
return getVariable(key: key, defaultValue: defaultValue).value
}
@available(*, deprecated, renamed: "variableValue()", message: "Use strictly typed versions of variableValue() methods")
public func variableValue<T>(key: String, defaultValue: T) -> T {
return getVariable(key: key, defaultValue: defaultValue).value
}

public func variable(key: String, defaultValue: Bool) -> DVCVariable<Bool> {
return getVariable(key: key, defaultValue: defaultValue)
Expand All @@ -306,6 +310,10 @@ public class DevCycleClient {
public func variable(key: String, defaultValue: NSDictionary) -> DVCVariable<NSDictionary> {
return getVariable(key: key, defaultValue: defaultValue)
}
@available(*, deprecated, renamed: "variable()", message: "Use strictly typed versions of variable() methods")
public func variable<T>(key: String, defaultValue: T) -> DVCVariable<T> {
return getVariable(key: key, defaultValue: defaultValue)
}

func getVariable<T>(key: String, defaultValue: T) -> DVCVariable<T> {
let regex = try? NSRegularExpression(pattern: ".*[^a-z0-9(\\-)(_)].*")
Expand Down
11 changes: 11 additions & 0 deletions DevCycleTests/Models/DevCycleClientTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,17 @@ class DevCycleClientTest: XCTestCase {
client.close(callback: nil)
}

func testVariableDeprecatedMethod() {
let client = try! self.builder.user(self.user).sdkKey("my_sdk_key").build(onInitialized: nil)
let defaultVal: Int = 1
let variable = client.variable(key: "key", defaultValue: defaultVal)
XCTAssertTrue(variable.value == defaultVal)
XCTAssertTrue(variable.isDefaulted)
let variableValue = client.variableValue(key: "key", defaultValue: defaultVal)
XCTAssertTrue(variableValue == defaultVal)
client.close(callback: nil)
}

func testVariableReturnsDefaultForUnsupportedVariableKeys() {
let client = try! self.builder.user(self.user).sdkKey("my_sdk_key").build(onInitialized: nil)
let variable = client.variable(key: "UNSUPPORTED\\key%$", defaultValue: true)
Expand Down

0 comments on commit 1ea7fc4

Please sign in to comment.