|
|
从项目中读plist文件
NSString *path = [[NSBundle mainBundle] pathForResource:@"heji" ofType:@"plist"];NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:path];NSLog(@"%@", [mutableDictionary objectForKey:@"he"]);NSLog(@"%@", [[mutableDictionary objectForKey:@"nihao"] objectForKey:@"d_1"]);NSLog(@"%@", [[mutableDictionary objectForKey:@"nihao"] objectForKey:@"d_2"]);NSLog(@"%@", [[mutableDictionary objectForKey:@"nihao"] objectForKey:@"d_3"]);NSLog(@"%@", [mutableDictionary objectForKey:@"ji"]);
在沙盒目录里创建并且读写
NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];[dic setValue:@"gagagag" forKey:@"key"];NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *myPath = [paths objectAtIndex:0];NSString *realpath = [myPath stringByAppendingPathComponent:@"test.plist"];[dic writeToFile:realpath atomically:YES];NSMutableDictionary *mutableDictionary1 = [[NSMutableDictionary alloc] initWithContentsOfFile:realpath];NSLog(@"%@", [mutableDictionary1 objectForKey:@"key"]); |
|