(一). 省市字典
1.创建文件接收路径.
NSString *path = @"/Users/dlios/Desktop/新OC/OC08_字典/OC08_字典/area(省市版).txt";
2.根据文件路径产生相应字符串.
NSError *error = nil;
NSString *str = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error];
// 判断如果错误出现,error不为空,打印错误信息.
if(error) {
NSLog(@"%@", error);
}
NSLog(@"%@", str)
3.将字符串切割成小的字符串放入数组中.
NSArray *array = [str componentsSeparatedByString:"@\n"];
4.创建省数组.
NSMutableArray *provinceArray = [NSMutableArray array];
5.遍历数组,找到符合条件的省名.
for (NSString *tempStr in array) {
// 如果前缀没有空格.
if (![tempStr hasPrefix:@" "])
// 创建省字典.
NSMutableDictionary *provinceDictionary = [NSMutableDictionary dictionary];
// 把找到的省名放入省字典(用key值标记:forKey:@"provinceName").
[provinceDictionary setObject:tempStr forKey:@"provinceName"];