You are mistakenly calling numberWithInt
with a NSNumber object, instead call setValue directly with that NSNumber
todayDate = [NSDate date];
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDateComponents* components = [calendar components:NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit fromDate:todayDate]; // Get necessary date components
//converting components
NSNumber *yearBuscado = [NSNumber numberWithInteger:[components year]];
NSNumber *mesBuscado = [NSNumber numberWithInteger:[components month]];
NSNumber *diaBuscado = [NSNumber numberWithInteger:[components day]];
[favoriteThing setValue:yearBuscado forKey:@"todoYear"];//Integer32
[favoriteThing setValue:mesBuscado forKey:@"todoMonth"];//Integer32
[favoriteThing setValue:diaBuscado forKey:@"todoDay"];//Integer32
Also, you can generate the Model Classes from CoreData Model. So that you can set values to a NSManagedObject
through Properties
instead of doing Key-Value Coding.
Like
FavoriteThing *favoriteThing = [NSEntityDescription insertNewObjectForEntityForName:@"FavoriteThing" inManagedObjectContext:[self managedObjectContext]];
[favoriteThing setBuscado: yearBuscado];