迭代器
数组
NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"2",@"3",@"4", nil];
NSEnumerator *enumerator =[arr objectEnumerator];
NSString *str =nil;
while (str=[enumerator nextObject]) {
NSLog(@"%@",str);
}
打印结果
2015-07-23 17:49:36.208 OC07_NSDate[1722:148494] 1
2015-07-23 17:49:36.209 OC07_NSDate[1722:148494] 2
2015-07-23 17:49:36.209 OC07_NSDate[1722:148494] 3
2015-07-23 17:49:36.209 OC07_NSDate[1722:148494] 4
打印字典的value
NSDictionary *dic=[NSDictionary dictionaryWithObjectsAndKeys:@"1",@"2",@"3",@"4", nil];
NSEnumerator *enumer =[dic objectEnumerator];
NSString *str =nil;
while (str=[enumer nextObject]) {
NSLog(@"%@",str);
}
打印结果
2015-07-23 17:58:49.490 OC07_NSDate[1738:151076] 1
2015-07-23 17:58:49.491 OC07_NSDate[1738:151076] 3
值对象
把基本数据类型转换成对象类型
NSInteger a=10;
NSNumber *number =[[NSNumber alloc] initWithInteger:a];
NSLog(@"%@",number);
NSInteger b=[number integerValue];
NSNumber *num=@10;
打印结果
2015-07-23 19:01:59.813 OC07_NSDate[1787:161605] 10
NSValue
把结构体和指针换成对象类型
结构体的.是访问成员变量,对象调用属性是点语法
NSRange range={2,5};
NSLog(@"%ld",range.length);
NSValue *value =[NSValue valueWithRange:range];
NSLog(@"%@",value);
NSRange rangeV=[value rangeValue];
打印结果
2015-07-23 19:06:35.140 OC07_NSDate[1794:163546] 5
2015-07-23 19:06:35.140 OC07_NSDate[1794:163546] NSRange: {2, 5}
int a=10;
int*p=&a;
NSValue *pointer=[NSValue valueWithPointer:p];
int *p1=[pointer pointerValue];
两个寻找路径
文档
{"reason":"success","result":[{"movieId":"216609","movieName":"诡八楼","pic_url":"http:\/\/v.juhe.cn\/movie\/picurl?2583083"},{"movieId":"216391","movieName":"摩登森林之美食总动员","pic_url":"http:\/\/v.juhe.cn\/movie\/picurl?2583246"},{"movieId":"216162","movieName":"龟兔再跑","pic_url":"http:\/\/v.juhe.cn\/movie\/picurl?2583181"},{"movieId":"215977","movieName":"森林孤影","pic_url":"http:\/\/v.juhe.cn\/movie\/picurl?2583247"},{"movieId":"215874","movieName":"从哪来,到哪去","pic_url":"http:\/\/v.juhe.cn\/movie\/picurl?2583542"},{"movieId":"215823","movieName":"有一天","pic_url":"http:\/\/v.juhe.cn\/movie\/picurl?2583092"},{"movieId":"215372","movieName":"兰辉","pic_url":"http:\/\/v.juhe.cn\/movie\/picurl?2583163"}
#
文件路径
NSString *path=@"/Users/dllo/Desktop/上课内容 /OC07_NSDate/OC07_NSDate/movielist.txt";
NSData *data=[NSData dataWithContentsOfFile:path];
NSMutableDictionary *dic=[NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(@"%@",dic);
NSMutableArray *arr=dic[@"result"];
NSLog(@"%@",arr);
NSDictionary *movieDic=arr[0];
NSLog(@"%@",movieDic);
NSString *str=movieDic[@"movieName"];
NSLog(@"%@",str);
NSString *movieName=dic[@"result"][1][@"movieName"];
NSLog(@"%@",movieName);
NSString *pic_url=dic[@"result"][1][@"pic_url"];
NSLog(@"%@",pic_url);
NSArray *arr=dic[@"result"];
for (NSDictionary *dic in arr) {
NSLog(@"%@",dic[@"movieName"]);
}
文档
{
"count": 20,
"start": 0,
"total": 4344,
"events": [
{
"image": "http://img3.douban.com/view/event_poster/median/public/10f53a2ad8b38c5.jpg",
"adapt_url": "http://www.douban.com/location/partner/event/21185304/",
"owner": {
"name": "国家博物馆",
"avatar": "http://img3.douban.com/view/site/small/public/6510ea4ea1cc8e6.jpg",
"uid": "127320",
"alt": "http://site.douban.com/127320/",
"type": "site",
"id": "127320",
"large_avatar": "http://img3.douban.com/pics/site/icon_default_large.png"
},
"loc_name": "北京",
"alt": "http://www.douban.com/event/21185304/",
"id": "21185304",
"category": "exhibition",
"title": "罗马与巴洛克艺术",
"wisher_count": 1975,
"has_ticket": false,
#
NSSet集合
NSSet是无序的
NSSet不能有重复的元素
集合里的元素必须是对象类型
NSSet *set=[NSSet setWithObjects:@"3",@"2",@"6",@"4",@"5",@"2", nil];
NSLog(@"%@",set);
NSLog(@"%ld",set.count);
NSLog(@"%@",[set anyObject]);
NSLog(@"%d",[set containsObject:@"3"]);
结果
2015-07-23 19:13:37.278 OC07_NSDate[1819:166400] {(
3,
6,
4,
2,
5
)}
2015-07-23 19:13:37.279 OC07_NSDate[1819:166400] 5
2015-07-23 19:13:37.279 OC07_NSDate[1819:166400] 3
2015-07-23 19:13:37.279 OC07_NSDate[1819:166400] 1
普通方式创建一个集合对象
NSSet *set=[[NSSet alloc]initWithObjects:@"1",@"2",@"3",@"4",@"5", nil ];
NSLog(@"%@",set);
可变集合
NSMutableSet *set=[NSMutableSet setWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
NSLog(@"%@",set);
[set addObject:@"6"];
NSLog(@"%@",set);
[set removeObject:@"3"];
NSLog(@"%@",set);
for (NSString *temp in set) {
NSLog(@"%@",temp);
}
NSDate
NSDate是一个日期的类
NSDate *date =[NS;
+date获取的时间无论在哪个区,都是打印相对应的零时区的时间
获取一下当前所在的时区
NSTimeZone *zone=[NSTimeZone systemTimeZone];
NSLog(@"%@",zone);
NSInteger seconds =[zone secondsFromGMTForDate:date];
NSLog(@"%ld",seconds);
NSDate *locatDate=[NSDate dateWithTimeIntervalSinceNow:seconds];
NSLog(@"%@",locatDate);
NSDate *tomorrowTime=[NSDate dateWithTimeIntervalSinceNow:(32*3600)];
NSLog(@"%@",tomorrowTime);
NSDate *yeaTime=[NSDate dateWithTimeIntervalSinceNow:(-16*3600)];
NSLog(@"%@",yeaTime);
NSDate *date1=[NSDate date];
NSDate *date2=[NSDate dateWithTimeIntervalSinceNow:1000];
NSTimeInterval interval =[date2 timeIntervalSinceDate:date1];
if (interval <= 60) {
NSLog(@"刚刚");
}else if (interval > 60 && interval <= 3600){
NSLog(@"%ld分钟以前",((NSInteger)interval / 60));
}else if (interval > 3600 && interval < (3600*24)){
NSLog(@"%ld小时以前",((NSInteger)interval / 3600));
}
把日期和字符串进行一个相互转换
NSDate->NSString
1.
NSDate *date =[NSDate date];
NSString *dateStr=[NSString stringWithFormat:@"%@",date];
NSLog(@"%@",dateStr);
2.时间的格式
yyyy-MM-dd hh-mm-ss
y年
M月
d日
h小时 H24小时 h12小时
m分钟
s秒
先设置时间的格式,要转换的时间和格式相吻合
NSDateFormatter *formatter=[[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd HH-mm-ss"];
NSString *timeStr=@"2015-7-23 17-18-10";
NSDate *date=[formatter dateFromString:timeStr];
NSLog(@"%@",date);