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的反射)