-1

我想将几个 NSArray 合并到一个 NSDictionary 中。这是我的数组:

@property (nonatomic, strong) NSArray *EuropeTable;
@property (nonatomic, strong) NSArray *AsiaTable;
@property (nonatomic, strong) NSArray *AfricaTable;
@property (nonatomic, strong) NSArray *LatinAmericaTable;
@property (nonatomic, strong) NSArray *NorthAmericaTable;

关于如何做到这一点的任何想法?

*编辑

我希望每个数组都有相同的键@“country”,这样我以后可以使用这个键

4

3 回答 3

3
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[dictionary setObject:self.EuropeTable forKey:@"EuropeTable"];
[dictionary setObject:self.AsiaTable forKey:@"AsiaTable"];
[dictionary setObject:self.AfricaTable forKey:@"AfricaTable"];
[dictionary setObject:self.LatinAmericaTable forKey:@"LatinAmericaTable"];
[dictionary setObject:self.NorthAmericaTable forKey:@"NorthAmericaTable"];

然后访问您需要的阵列之一:

NSArray *europeTable = [dictionary objectForKey:@"EuropeTable"];


更新:

NSArray *array = [NSArray arrayWithObjects:self.EuropeTable,
                                           self.AsiaTable,
                                           self.AfricaTable, 
                                           self.LatinAmericaTable,
                                           self.NorthAmericaTable, nil];

NSDictionary *dict = [NSDictionary dictionaryWithObject:array forKey:@"country"];
于 2012-05-08T14:16:09.457 回答
2
NSDictionary *countries =
  [NSDictionary dictionaryWithObjectsAndKeys:
    EuropeTable, @"You",
    AsiaTable, @"Need To",
    AfricaTable, @"Provide",
    LatinAmericaTable @"More",
    NorthAmericaTable, @"Details",
    nil];

没有更多细节,我不确定任何答案会对您有多大帮助:)

于 2012-05-08T14:14:28.853 回答
0
NSMutableDictionary dict = [NSMutableDictionary dictionary];
[dict addObject:self.EuropeTable forKey:@"EuropeTable"];
etc...
于 2012-05-08T14:13:43.157 回答