-2

I need some kind of help with an explanation to understand how use a NSDirectory, i don´t know if is possible to insert a NSString or NSDictionary's data from a class "A" in another NSDictionary in class B

Class A

String
NSString *TwitterToken = accessTokenTwt;
NSString *twitterSecretToken = accessTokenSecret;

NSDictionary take the tokenExpires or another

- (NSMutableDictionary *)tokenAsDictionary
{
NSMutableDictionary *tokenDictionary = [[NSMutableDictionary alloc] init];

tokenDictionary[@"key"] = self.key;
tokenDictionary[@"secret"] = self.secret;
tokenDictionary[@"tokenExpires"] = @(self.tokenExpires);
tokenDictionary[@"requestAuthUrl"] = self.requestAuthUrl;
if (self.verifier) {
    tokenDictionary[@"verifier"] = self.verifier;
}

return tokenDictionary;
}

Class B

NSMutableDictionary *args = [[NSMutableDictionary alloc] init];

    [args setObject: [Insert here data from class A] forKey:@"access_token"];
    [args setObject: @"1" forKey:@"expires"];

1 Answers1

1

An NSMutableDictionary (or NSDictionary) can have any object as the value: strings, dictionaries, arrays, etc. Regardless of the type, you retrieve it exactly the same. If you store a dictionary in there, you just need to drill in one more level to see that dictionary's data (you'll have to cast it to a dictionary though).

Psuedo code ensuing...

Dictionary a = ...;
a[@"keyA"] = "hi A";
Dictionary b = ...;
b[@"keyB"] = a;

// You now have the dictionary "a" stored inside dictionary "b" with a key of "keyB".

Dictionary c = b[@"keyB"];

// Dictionary c is now, essentially, Dictionary a

// c[@"keyA"] will return to you "hi A"
ghostatron
  • 2,620
  • 23
  • 27