Matt Douhan
Matt Douhan

Reputation: 2113

NSDictionary seems to have multiple values for one key, how do I access the individual values?

I am using ADAL to authenticate to Azure AD, it returns an dictionary with claims, one of the keys is the groups that a user is a member of,

The full dictionary looks like this

2017-06-05 17:40:58.712 NWMobileTill[46676:3282242] userInfoStore Item all {
    alg = none;
    amr =     (
        pwd
    );
    aud = "042a00fc-b832-411f-xxxxxxxx";
    exp = xxxxxxx;
    groups =     (
        "xxx-9725-43f6-a502-xxxxx",
        "38c5b3af-xxx-4b38-b180-xxxx"
    );
    iat = xxx;
    ipaddr = "xx";
    iss = "https://xxxxxxx/xxx-d61d-xxx-a949-0cb72eff23be/";
    name = "POS Test";
    nbf = xxx;
    oid = "c44f91f2-xx-40bb-9624-xxx";
    platf = 2;
    sub = "xxxxx";
    tid = "b5154a9e-xxx-4d55-a949-xxx";
    typ = JWT;
    "unique_name" = "nwpos@xxxxxx";
    upn = "nwpos@xxxx";
    ver = "1.0";
}

when I access they values in the NSDIctionary using the objectForKey as below

NSDictionary *jongel = [result.tokenCacheStoreItem.userInformation.allClaims objectForKey:@"groups"];

I get multiple entries like this,

2017-06-05 17:40:58.712 NWMobileTill[46676:3282242] Groups are (
"xx-9725-43f6-a502-xx",
"xx-d0dc-4b38-xx-17555db6f626"
)

I am confused that I can get multiple values, how do I access each individual value? I happen to assign this to an NSDictionary but I don't know if that is right. How can I get to those individual entries?

Upvotes: 0

Views: 140

Answers (1)

Nicholas Smith
Nicholas Smith

Reputation: 11754

The groups is an array, so when you do the [objectForKey...] call it returns the data as expected. I would assign the returned object to an NSArray as it should always be returned as from that data model as an array, even if it only contains one element. If you're more curious you can add a breakpoint in and examine it in a debugger, the [objectForKey...] method does some interesting behaviour around type conversions and sometimes the results may surprise you.

Upvotes: 2

Related Questions