访问Plist中的坐标 - iOS

时间:2013-07-19 18:05:53

标签: ios nsmutablearray plist

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

 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中。

enter image description here

1 个答案:

答案 0 :(得分: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"]);

    }
}