-5

而不是使用硬编码访问特定纬度,如下所示

 NSString *path = [[NSBundle mainBundle] pathForResource:
                  @"WellList" ofType:@"plist"];
NSMutableDictionary *root = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSString* latitude = [[[[[root objectForKey: @"Routes"] objectForKey: @"Houston" ] objectForKey: @"Location 1"] objectForKey: @"coordinate"] objectForKey: @"latitude"]; 

我想使用循环来访问我的 plist 中的每个坐标并将它们添加到我的 NSmutableArray 中。

在此处输入图像描述

4

1 回答 1

1
NSMutableDictionary *root = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
NSDictionary *routes = [root objectForKey: @"Routes"];
NSArray *cities = [routes allValues];
for (NSDictionary *city in cities) {
    NSArray *locations = [city allValues];
    for (NSDictionary *loc in locations) {
        NSDictionary *coord = [loc objectForKey:@"coordinate"];
        NSLog(@"%@",[coord objectForKey:@"latitude"]);

    }
}
于 2013-07-19T18:17:11.123 回答