而不是使用硬编码访问特定纬度,如下所示
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中。
答案 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"]);
}
}