0
CD에서 내 날짜를 가져 오는 데 문제가 있습니다.코어 데이터에서 날짜를 가져 오기
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"dd-mm-yyyy"];
NSString *dateStr;
NSLog(@"%@",datesDictionary);
for (NSDictionary *diction in datesDictionary) {
if ([diction objectForKey:@"date"]) {
ImportantDate *newDate = (ImportantDate *)[NSEntityDescription insertNewObjectForEntityForName:@"ImportantDate" inManagedObjectContext:_managedObjectContext];
newDate.id = [NSNumber numberWithInt:[NSLocalizedString([diction objectForKey:@"id"], nil) intValue]];
dateStr = NSLocalizedString([diction objectForKey:@"date"], nil);
NSLog(@"dateStr: %@",dateStr);
newDate.date = [formatter dateFromString:dateStr];
NSLog(@"Date: %@",newDate.date);
newDate.dayOfTheWeek = NSLocalizedString([diction objectForKey:@"dayOfTheWeek"], nil);
newDate.eventType = NSLocalizedString([diction objectForKey:@"eventType"], nil);
}
}
내 코드에서 dateStr
을 로깅 할 때 잘 기록됩니다. 그러나 내가 로그 할 때 newDate.date
널 값을 얻는다.
내 값의 나머지는 int 또는 문자열이됩니다.
아이디어가 있으십니까?
dateStr에 대한 NSLog 출력을 표시하십시오 –
'-insertNewObjectForEntityForName : inManagedObjectContext :'의 결과를 캐스팅 할 필요가 없습니다. 이 호출은'id'를 반환합니다. –
또한'ImportantDate'에'id'라는 속성이 있습니다. ** 강력하게 ** 이름을 바꾸는 것이 좋습니다 **. 'id'는 예약어입니다. –