码迷,mamicode.com
首页 > 其他好文 > 详细

OC -- NSCalendar的使用 与OC的反射

时间:2016-01-27 19:30:29      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:

 NSDate *date = [NSDate date];

        NSLog(@"%@", date);

        NSCalendar *ca = [NSCalendar currentCalendar];

        NSDateComponents *res = [ca components:NSCalendarUnitYear fromDate:date];

        NSLog(@"%ld", res.year);

        NSDateComponents *res2 = [ca components:NSCalendarUnitMonth fromDate:date];

        NSLog(@"%ld", res2.month);

        NSCalendarUnit unit = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;

        NSDateComponents *res3 = [ca components:unit fromDate:date];

        NSLog(@"%ld--%ld--%ld", res3.year, res3.month, res3.day);

        NSLog(@"%ld:%ld:%ld", res3.hour, res3.minute, res3.second);

// 反射reflect

        NSString *str = @"Person";

        Class class = NSClassFromString(str);

        Person *p = [[class alloc] init];

        NSLog(@"%@", [p class]);

        NSString *str2 = NSStringFromClass([p class]);

        NSLog(@"%@", str2);

        // 方法的反射

        NSString *method = @"say";

        SEL sel = NSSelectorFromString(method);

        [p performSelector:sel];

OC -- NSCalendar的使用 与OC的反射

标签:

原文地址:http://www.cnblogs.com/lianfu/p/5163992.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!