You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.7 KiB

9 years ago
//
// CLTimezoneData.m
// Clocker
//
// Created by Abhishek Banthia on 12/22/15.
//
//
#import "CLTimezoneData.h"
9 years ago
#import "CommonStrings.h"
9 years ago
@implementation CLTimezoneData
9 years ago
-(instancetype)initWithDictionary:(NSDictionary *)dictionary
9 years ago
{
9 years ago
if (self == [super init])
{
self.customLabel = dictionary[CLCustomLabel];
self.sunriseTime = CLEmptyString;
self.sunsetTime = CLEmptyString;
self.timezoneID = dictionary[CLTimezoneName];
self.latitude = dictionary[@"latitude"];
self.longitude = dictionary[@"longitude"];
self.place_id = dictionary[CLPlaceIdentifier];
self.formattedAddress = dictionary[CLTimezoneName];
}
9 years ago
9 years ago
return self;
9 years ago
}
- (BOOL)saveObjectToPreferences:(CLTimezoneData *)object
{
NSData *encodedObject = [NSKeyedArchiver archivedDataWithRootObject:object];
NSMutableArray *array = [NSMutableArray new];
[array addObject:encodedObject];
[[NSUserDefaults standardUserDefaults] setObject:array forKey:@"checking"];
[self getCustomObject];
return YES;
}
- (void)getCustomObject
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSArray *encodedObject = [defaults objectForKey:@"checking"];
CLTimezoneData *object = [NSKeyedUnarchiver unarchiveObjectWithData:encodedObject[0]];
NSLog(@"Object:%@", object.place_id);
}
- (void)encodeWithCoder:(NSCoder *)coder
{
[coder encodeObject:self.place_id forKey:@"place_id"];
[coder encodeObject:self.formattedAddress forKey:@"formattedAddress"];
[coder encodeObject:self.customLabel forKey:@"customLabel"];
[coder encodeObject:self.sunriseTime forKey:@"sunriseTime"];
[coder encodeObject:self.sunsetTime forKey:@"sunsetTime"];
[coder encodeObject:self.timezoneID forKey:@"timezoneID"];
}
- (instancetype)initWithCoder:(NSCoder *)coder
{
if (self == [super init])
{
self.place_id = [coder decodeObjectForKey:@"place_id"];
self.formattedAddress = [coder decodeObjectForKey:@"formattedAddress"];
self.customLabel = [coder decodeObjectForKey:@"customLabel"];
self.sunsetTime = [coder decodeObjectForKey:@"sunsetTime"];
self.sunriseTime = [coder decodeObjectForKey:@"sunriseTime"];
self.timezoneID = [coder decodeObjectForKey:@"timezoneID"];
}
return self;
}
9 years ago
-(NSString *)description
{
return [NSString stringWithFormat:@"TimezoneID:%@\nFormatted Address:%@\nCustom Label:%@\nLatitude:%@\nLongitude:%@\nSunrise:%@\nSunset:%@\nPlaceID:%@", self.timezoneID,
self.formattedAddress,
self.customLabel,
self.latitude,
self.longitude,
self.sunriseTime,
self.sunsetTime,
self.place_id];
}
9 years ago
@end