diff --git a/DevCycle/DevCycleClient.swift b/DevCycle/DevCycleClient.swift index 854de05..c2583fd 100644 --- a/DevCycle/DevCycleClient.swift +++ b/DevCycle/DevCycleClient.swift @@ -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(key: String, defaultValue: T) -> T { + return getVariable(key: key, defaultValue: defaultValue).value + } public func variable(key: String, defaultValue: Bool) -> DVCVariable { return getVariable(key: key, defaultValue: defaultValue) @@ -306,6 +310,10 @@ public class DevCycleClient { public func variable(key: String, defaultValue: NSDictionary) -> DVCVariable { return getVariable(key: key, defaultValue: defaultValue) } + @available(*, deprecated, renamed: "variable()", message: "Use strictly typed versions of variable() methods") + public func variable(key: String, defaultValue: T) -> DVCVariable { + return getVariable(key: key, defaultValue: defaultValue) + } func getVariable(key: String, defaultValue: T) -> DVCVariable { let regex = try? NSRegularExpression(pattern: ".*[^a-z0-9(\\-)(_)].*") diff --git a/DevCycleTests/Models/DevCycleClientTests.swift b/DevCycleTests/Models/DevCycleClientTests.swift index a2ae961..8d4708c 100644 --- a/DevCycleTests/Models/DevCycleClientTests.swift +++ b/DevCycleTests/Models/DevCycleClientTests.swift @@ -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)