2016-03-29 16 views
-2

Ich brauche irgendeine Art von Hilfe mit einer Erklärung zu verstehen, wie ein NSDirectory verwenden, ich weiß nicht, ob es möglich ist, ein NSString oder NSDictionary Daten aus einer Klasse "A" in einem anderen NSDictionary in Klasse BNSDictionary verwenden

einfügen

Klasse 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; 
} 

Klasse B

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

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

Ja sicher, dass Sie eine NSDictionary zu einem anderen NSDictionary –

+0

Dank hinzufügen können! aber wie kann ich das Wörterbuch von Klasse A bekommen –

Antwort

1

Ein NSMutableDictionary (oder NSDictionary) kann als Wert jedes Objekt haben: strings, Wörterbücher, Arrays, usw. Unabhängig von der ty pe, du bekommst es genau gleich. Wenn Sie ein Wörterbuch darin speichern, müssen Sie nur noch eine weitere Ebene aufrufen, um die Daten des Wörterbuchs zu sehen (Sie müssen es jedoch in ein Wörterbuch umwandeln).

Psuedo Code folgenden ...

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"