Getting hours during the day
Instead of handling all the different cases (am, pm, special rules for
midnight and noon) you can use a date formatter which does all these
things for you:

NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"ha"; // h = 0..12, a = am/pm

NSString *string = [fmt stringFromDate:someDate];


Then note that not all people use the 12hour AM/PM system. You might
consider to display the hours according to the locale/region that a user has
configured on his computer. That is achieved simply by using the date format

fmt.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"h" options:0 locale:[NSLocale currentLocale]];


Another problem occurs when the clock is adjusted for the daylight
saving time. For example, when DST starts in Germany, the hour is
put forward at 2am by one hour, so that the time "2am" does not exist
at all. Similarly, when DST ends and the hour is put back at 3am by
one hour, then time "2am" occurs twice.

Therefore, instead of simply incrementing an "hour" variable, I would
recommend to use calendrical calculations which handle all these
situations correctly:

// A date formatter that prints hours according to the user's locale/region settings:
NSDateFormatter *fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = [NSDateFormatter dateFormatFromTemplate:@"h" options:0 locale:[NSLocale currentLocale]];

NSCalendar *calendar = [NSCalendar currentCalendar];

// The last hour to print is the full hour of the current point in time:
NSDate *lastHour;
[calendar rangeOfUnit:NSCalendarUnitHour startDate:&amp;lastHour interval:nil forDate:[NSDate date]];

// The first hour to print is one day earlier:
NSDate *firstHour = [calendar dateByAddingUnit:NSCalendarUnitDay value:-1 toDate:lastHour options:0];

NSMutableArray *units = [[NSMutableArray alloc] init];

// hour = firstHour ... lastHour:
NSDate *hour = firstHour;
do {
    [units addObject:[fmt stringFromDate:hour]];

    // Add one hour:
    hour = [calendar dateByAddingUnit:NSCalendarUnitHour value:1 toDate:hour options:0];
} while ([hour compare:lastHour] != NSOrderedDescending); // while hour &lt;= lastHour