Guest User

Untitled

a guest
Jan 19th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. __dataArea = [NSMutableData data];
  2. __unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:__dataArea];
  3. __archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:__dataArea];
  4.  
  5. __iDates = [[BCimportantDates alloc] initWithCoder:[NSKeyedUnarchiver unarchiveObjectWithFile: @"firstDate.arch"]];
  6.  
  7. if ((__iDates.firstDate == nil)){
  8.  
  9. NSDate *date = [NSDate date];
  10. NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
  11. NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];
  12. NSLog(@"the date %@",date);
  13. [components setHour: 3];
  14. [components setMinute: 00];
  15. [components setSecond: 00];
  16. __newDate = [gregorian dateFromComponents: components];
  17. [__iDates setFirstDate: __newDate];
  18. NSLog(@"%@",__iDates.firstDate);
  19. [__iDates encodeWithCoder: __archiver];
  20. [__archiver finishEncoding];
  21. if ([__dataArea writeToFile:@"firstDate.arch" atomically:YES] == NO){
  22. NSLog(@"archiving failed. ");
  23. }
  24. }
  25.  
  26. - (void) encodeWithCoder:(NSCoder *)encoder{
  27. [encoder encodeObject: __firstDate forKey: kfirstDateKey];
  28. }
  29.  
  30. - (id) initWithCoder: (NSCoder *) decoder{
  31. if (self = [super init]) {
  32. self.firstDate = [decoder decodeObjectForKey:kfirstDateKey];
  33. }
  34. return self;
  35. }
  36.  
  37. NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:@"firstDate.arch"];
  38.  
  39. if ([__dataArea writeToFile:path atomically:YES] == NO){
  40. NSLog(@"archiving failed. ");
  41. }
Add Comment
Please, Sign In to add comment