NSDictionary和NSMutableDictionary

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
// NSDictionary *dic=[NSDictionary dictionaryWithObject:@"lnj" forKey:@"name"];
// NSString *name=[dic objectForKey:@"name"];
// NSLog(@"name=%@",name); // NSDictionary *dic=[NSDictionary dictionaryWithObjects:@[@"lnj",@"30"] forKeys:@[@"name",@"age"]];
// NSLog(@"%@,%@",[dic objectForKey:@"name"],[dic objectForKey:@"age"]); // NSDictionary *dic =@{@"name":@"lnj"};
// NSLog(@"%@",dic[@"name"]); // NSDictionary *dic=@{@"name":@"lnj",@"age":@"30",@"height":@"1.75"};
// NSLog(@"%@,%@,%@",dic[@"name"],dic[@"age"],dic[@"height"]); //字典的遍历
// NSLog(@"count=%lu",[dic count]);
// for (int i=0; i<dic.count; i++) {
// NSArray *keys=[dic allKeys];
// NSString *key=keys[i];
// NSString *value=dic[key];
// NSLog(@"%@,%@",key,value);
//
// }
// for (NSObject *key in dic) {
//// NSLog(@"%@",key);
// NSString *value=dic[key];
// NSLog(@"%@,%@",key,value);
// } //字典和数组不同,字典中保存的数据是无序的
// [dic enumerateKeysAndObjectsUsingBlock:^(id key,id value,BOOL *stop) {
// NSLog(@"%@,%@",key,value);
//
// }]; //3.字典文件读写
NSDictionary *dic=@{@"name":@"lnj",@"age":@"",@"height":@"1.75"};
[dic writeToFile:@"/Users/qianlilin/Desktop/info.plist" atomically:YES]; NSDictionary *newDict=[NSDictionary dictionaryWithContentsOfFile:@"/Users/qianlilin/Desktop/info3.plist"];
NSLog(@"%@",newDict);
// NSArray *arr=@[@10,@20,@5];
// [arr writeToFile:@"/Users/qianlilin/Desktop/info1.plist" atomically:YES];
// NSArray *newArray=[NSArray arrayWithContentsOfFile:@"/Users/qianlilin/Desktop/info2.plist"];
// NSLog(@"%@",newArray);
}
return ;
}
#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
// NSMutableArray *arrM=[NSMutableArray arrayWithObject:@"qll"];
NSMutableArray *arrM=[NSMutableArray array];
[arrM addObject:@"JJJ"];
NSLog(@"%@",arrM);
[arrM addObjectsFromArray:@[@"lmj",@"lnj"]];
NSLog(@"%@",arrM); // [arrM addObject:@[@"lmj",@"lnj"]];
// NSLog(@"%@",arrM); [arrM insertObject:@"xcp" atIndex:];
NSLog(@"%@",arrM); NSRange range=NSMakeRange(, );
NSIndexSet *set=[NSIndexSet indexSetWithIndexesInRange:range];
[arrM insertObjects:@[@"",@""] atIndexes:set];
NSLog(@"%@",arrM); [arrM removeObject:@""];
NSLog(@"%@",arrM); [arrM removeLastObject];
NSLog(@"%@",arrM); [arrM removeObjectAtIndex:];
NSLog(@"%@",arrM); [arrM replaceObjectAtIndex: withObject:@"M"];
NSLog(@"%@",arrM); NSLog(@"%@",[arrM objectAtIndex:]); NSLog(@"%@",arrM[]); arrM[]=@"";
NSLog(@"%@",arrM[]);
}
return ;
}

上课所写

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
@autoreleasepool {
// NSDictionary *dii=@{@"a":@"*"};
// NSDictionary *dii1=@{@"a":@"长城"};
// NSArray *c=@[dii,dii1];
// NSDictionary *dic=@{@"city":@"北京市",@"Citys":c};
// NSArray *arr=@[dic];
// [arr writeToFile:@"/Users/qianlilin/Desktop/info4.plist" atomically:YES]; NSString *path=@"/Users/qianlilin/Desktop/city.plist";
NSArray *arr=[NSArray arrayWithContentsOfFile:path];
/* for (NSDictionary *a in arr) {
// NSLog(@"%@",a); NSArray *CI=[a objectForKey:@"Citys"];
NSLog(@"%@",[a objectForKey:@"city"]);
for (NSDictionary *cc in CI) {
// NSLog(@"%@",cc);
NSLog(@"%@",[cc objectForKey:@"a"]); }
}*/ for (NSDictionary *china in arr) {
// NSLog(@"%@",a);
NSArray *CI=[china objectForKey:@"Cities"];
NSLog(@"%@",china[@"State"]);
// NSLog(@"%@",cc);
for (NSDictionary *cc in CI) {
NSLog(@"%@",[cc objectForKey:@"city"]);
}
} }
return ;
}
上一篇:[转]ANDROID仿IOS微信滑动删除_SWIPELISTVIEW左滑删除例子


下一篇:仿QQ列表左滑删除