週ごとのグラフでデータを取得するためにこれが必要です。これは私にはうまくいきません。返される日付は、選択した年の 1 月 1 日です。何かアイデアはありますか?
-(NSDate*) getFirstDateOfTheWeek:(NSString*) weekNr andYear: (NSString*) theYear {
int intYear = [theYear intValue];
int intWeek = [weekNr intValue];
NSCalendar *gregorian = [[NSCalendar alloc]
initWithCalendarIdentifier:NSGregorianCalendar];
[gregorian setLocale:[NSLocale currentLocale]];
NSDateComponents * comp = [[NSDateComponents alloc] init];
[comp setYear:intYear];
[comp setWeek:intWeek];
NSDate *dateOfFirstDay = [gregorian dateFromComponents:comp];
NSDateComponents *dateComponents =
[gregorian components:NSWeekdayCalendarUnit|NSWeekCalendarUnit|NSDayCalendarUnit|NSYearCalendarUnit|NSMonthCalendarUnit fromDate:dateOfFirstDay];
int year = [dateComponents year];
int month = [dateComponents month];
int day = [dateComponents day];
dateOfFirstDay= [gregorian dateFromComponents:dateComponents];
return dateOfFirstDay;
}