Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading