Created
July 6, 2018 12:16
-
-
Save g761007/74e4fe342dd1a21f0515add2f4120c26 to your computer and use it in GitHub Desktop.
The NSDate extension for calculating the age.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSDate+Age.h | |
// | |
// Created by Daniel Hsieh on 2018/7/6. | |
// | |
#import <Foundation/Foundation.h> | |
@interface NSDate (Age) | |
- (NSInteger)age; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// NSDate+Age.m | |
// | |
// Created by Daniel Hsieh on 2018/7/6. | |
// | |
#import "NSDate+Age.h" | |
@implementation NSDate (Age) | |
- (NSInteger)age { | |
return [[NSCalendar currentCalendar] components:NSCalendarUnitYear | |
fromDate:self | |
toDate:[NSDate date] | |
options:0].year; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment