Created
September 11, 2014 09:07
-
-
Save Legoless/0b694b5a45a12c8a1971 to your computer and use it in GitHub Desktop.
Weak or strong property?
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
@interface DateObject : NSObject | |
@property (nonatomic, strong) NSDate *date_UTC; | |
// Wrapper property, strong or weak? | |
@property (nonatomic) NSDate *date; | |
@end | |
@implementation DateObject | |
- (void)setDate:(NSDate *)date | |
{ | |
// | |
// The date is transformed to UTC retaining only the day, month, year | |
// | |
// - Get components from local calendar | |
// - Insert components into the UTC calendar | |
// - Get date | |
// | |
NSDateComponents *components = [[NSCalendar autoupdatingCurrentCalendar] component:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:date]; | |
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
gregorian.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; | |
NSDate *resampledDate = [gregorian dateFromComponents:components] | |
self.date_UTC = resampledDate; | |
} | |
- (NSDate *)date | |
{ | |
// | |
// The date is transformed from UTC retaining only the day, month, year | |
// | |
// - Get components from UTC calendar | |
// - Insert components into the local calendar | |
// - Get date | |
// | |
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; | |
gregorian.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0]; | |
NSDateComponents *components = [gregorian components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:self.date_UTC]; | |
return [[NSCalendar autoupdatingCurrentCalendar] dateFromComponents:components]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment