-1

複数の NSArray を 1 つの 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"];

次に、必要な配列の 1 つにアクセスするには、次の操作を行う必要があります。

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 に答える