OC -- NSCalendar的使用 与OC的反射
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OC -- NSCalendar的使用 与OC的反射相关的知识,希望对你有一定的参考价值。
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的反射的主要内容,如果未能解决你的问题,请参考以下文章