Skip to content

Commit

Permalink
Move the reading of the user object's properties to public scope (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
z4kn4fein authored Jun 6, 2024
1 parent 502954c commit 9ea82c3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
18 changes: 13 additions & 5 deletions Sources/ConfigCat/ConfigCatUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import Foundation

/// User Object. Contains user attributes which are used for evaluating targeting rules and percentage options.
public final class ConfigCatUser: NSObject {
static let idKey: String = "Identifier"
static let emailKey: String = "Email"
static let countryKey: String = "Country"
@objc public static let idKey: String = "Identifier"
@objc public static let emailKey: String = "Email"
@objc public static let countryKey: String = "Country"

private var attributes: [String: Any]
private(set) var identifier: String

/// The user object's identifier.
public private(set) var identifier: String

/**
Initializes a new `ConfigCatUser`.
Expand Down Expand Up @@ -76,7 +78,13 @@ public final class ConfigCatUser: NSObject {
self.identifier = custom[ConfigCatUser.idKey] as? String ?? ""
}

func attribute(for key: String) -> Any? {
/**
Returns the user attribute value identified by the given key.

- Parameter key: The key of the user attribute.
- Returns: The user attribute value.
*/
@objc public func attribute(for key: String) -> Any? {
if key.isEmpty {
assert(false, "key cannot be empty")
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/ConfigCatTests/ConfigCatClientIntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ConfigCatClientIntegrationTests: XCTestCase {
XCTAssertEqual("@configcat.com", details.matchedTargetingRule?.conditions[0].userCondition?.stringArrayValue?.first)
XCTAssertNil(details.matchedPercentageOption)
XCTAssertEqual(2, details.matchedTargetingRule?.conditions[0].userCondition?.comparator.rawValue)
XCTAssertEqual(user.identifier, details.user?.identifier)
XCTAssertEqual(user.attribute(for: ConfigCatUser.idKey) as! String, details.user?.attribute(for: ConfigCatUser.idKey) as! String)
called = true
}
let client = ConfigCatClient.get(sdkKey: "PKDVCLf-Hq-h-kCzMp-L7Q/psuH7BGHoUmdONrzzUOY7A", options: config)
Expand Down

0 comments on commit 9ea82c3

Please sign in to comment.