Accessing Coordinates in Plist - iOS [closed]

。_饼干妹妹 提交于 2019-12-14 04:15:16

问题


Instead of accessing specific latitude with hardcoded as shown in below

 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"]; 

I would like to use loop to access every single coordinate in my plist and add them into my NSmutableArray.


回答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"]);

    }
}


来源:https://stackoverflow.com/questions/17752710/accessing-coordinates-in-plist-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!