本文介绍了在Plist中访问坐标-iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
而不是使用如下所示的硬编码访问特定纬度
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"];
我想使用循环访问plist中的每个坐标并将其添加到我的NSmutableArray中.
I would like to use loop to access every single coordinate in my plist and add them into my NSmutableArray.
推荐答案
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"]);
}
}
这篇关于在Plist中访问坐标-iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!