Get the date of sunday of the current week in IOs

I have searched for the solution to find the date of the sunday of the particular week.I have found questions that have been answered but it doesnt show the correct date of sunday.

NSCalendar *calendar = [NSCalendar currentCalendar];
unsigned unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth |  NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekday | NSCalendarUnitWeekOfYear;
NSDateComponents *comps = [calendar components:unitFlags fromDate:[NSDate date]];
comps.weekday = 1;  //Sunday
comps.weekOfMonth = 1;
NSDate *sundayDate = [calendar dateFromComponents:comps];

When i print out the date it gives this.

  • How to calculate percentage using % as a postfix unary operator in Swift 3 and still be able to use % for modulo?
  • ios store ^block in dictionary or array?
  • How can I launch Safari from an iPhone app?
  • Download dSYM fails “Missing App Version”
  • Creating iOS/OSX Frameworks: is it necessary to codesign them before distributing to other developers?
  • How to animate a button change in UINavigationBar?
  • 2015-07-08 10:14:00 +0000

    Its the current date.What am i doing wrong?

    Solutions Collect From Internet About “Get the date of sunday of the current week in IOs”

    hope this helps you :

        NSDate *today = [NSDate date];
        NSCalendar *calenderObj = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
        calenderObj.firstWeekday = 1; // Sunday = 1, 
         // NSDateComponents *components = [calenderObj components:NSWeekOfYearCalendarUnit fromDate:today];
        NSDate *objDate = nil;
     [calenderObj rangeOfUnit:NSWeekCalendarUnit startDate:&objDate interval:NULL forDate:today];
        NSLog(@" === %@",  objDate);

    Output :

    === 2015-07-15 10:26:00 +0000