【代码笔记】iOS-plist获得城市列表

一,工程图。

二,代码。

复制代码
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    NSString* cityPlistPath = [[NSBundle mainBundle] pathForResource:@"cities" ofType:@"plist"];
    
    //按照拼写排序,spell是英文拼写
    NSSortDescriptor *bySpell  = [NSSortDescriptor sortDescriptorWithKey:@"spell" ascending:YES];
    NSArray *cities = [[NSArray arrayWithContentsOfFile:cityPlistPath] sortedArrayUsingDescriptors:@[bySpell]];
    NSLog(@"--cities--%@",cities);
    
}
复制代码
原文地址:https://www.cnblogs.com/yang-guang-girl/p/7940257.html