NS词典使用
NSDictionary use
我需要某种帮助来解释如何使用 NSDirectory,我不知道是否可以从 class "A" 中插入 NSString 或 NSDictionary 的数据class B
中的 NSDictionary
Class一个
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乙
NSMutableDictionary *args = [[NSMutableDictionary alloc] init];
[args setObject: [Insert here data from class A] forKey:@"access_token"];
[args setObject: @"1" forKey:@"expires"];
一个NSMutableDictionary(或NSDictionary)可以有任何对象作为值:字符串、字典、数组等。不管是什么类型,你检索它都是一样的。如果您在其中存储字典,则只需再钻一个级别即可查看该字典的数据(不过您必须将其转换为字典)。
随后的伪代码...
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"
我需要某种帮助来解释如何使用 NSDirectory,我不知道是否可以从 class "A" 中插入 NSString 或 NSDictionary 的数据class B
中的 NSDictionaryClass一个
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乙
NSMutableDictionary *args = [[NSMutableDictionary alloc] init];
[args setObject: [Insert here data from class A] forKey:@"access_token"];
[args setObject: @"1" forKey:@"expires"];
一个NSMutableDictionary(或NSDictionary)可以有任何对象作为值:字符串、字典、数组等。不管是什么类型,你检索它都是一样的。如果您在其中存储字典,则只需再钻一个级别即可查看该字典的数据(不过您必须将其转换为字典)。
随后的伪代码...
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"