| categories:littlist objective-c develop

Reminder:日時の書き込み

リマインダーへの日時の書き込み

読み込み時には

event.dueDate = eventToRead.dueDateComponents.date;
event.timeZone = eventToRead.dueDateComponents.timeZone;

と、あっさりと行くのですが、.dueDateComponents.date は readonly で書き込み時には日時をバラバラにしてまとめて書き込みます。


  NSCalendar *gregorian = [[NSCalendar alloc]
                           initWithCalendarIdentifier:NSGregorianCalendar];
  unsigned unitFlags= NSYearCalendarUnit|NSMonthCalendarUnit | NSDayCalendarUnit |
   NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit |NSTimeZoneCalendarUnit;
  
  NSDateComponents *dailyComponents=[gregorian components:unitFlags fromDate:eventToExport.dueDate];
  
  eventToWrite.dueDateComponents = dailyComponents;
  eventToWrite.timeZone = eventToExport.timeZone;
  
comments powered by Disqus