Search code examples
iosnscalendarnsdatecomponents

Detect If between time periods


I'm having issue with the code below. What's the issue with it? I have tried defining the NSUInteger as an int, but it still didn't work.

NSCalendar *cal = [NSCalendar currentCalendar];
NSDateComponents *components = [cal components:NSHourCalendarUnit fromDate:nowNow];
NSLog(@"%ld",[components hour]);
NSUInteger *timeHour = [components hour];
if ( timeHour < 5 &&  timeHour > 9){}

This piece of code is supposed to detect wether it's between 5, and 9 in the morning.


Solution

  • I fixed this issue by replacing the 'if' line with:

    if ( [components hour] <= 5 && [components hour] >= 9){
    

    and removing the NSUInteger line.