2016-03-29 5 views
-2

NSDirectoryの使い方を理解するために何か助けが必要ですが、NSStringやNSDictionaryのデータをクラスAの別のNSDictionaryのクラスBに挿入することが可能かどうか分かりませんNSDictionary use

クラス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; 
} 

クラスB

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

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

はいあなたは別のNSDictionaryの –

+0

感謝にNSDictionaryのを追加することができます!私はクラスAから辞書を得ることができます –

答えて

1

アンNSMutableDictionary(またはNSDictionaryの)値として任意のオブジェクトを有することができる:等の文字列、辞書、配列、にかかわらずTYのあなたはまったく同じものを取得します。辞書をそこに格納する場合は、その辞書のデータを見るためにさらに1つのレベルでドリルするだけで済みます(ただし、それを辞書にキャストする必要があります)。

擬コード続く...

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"