Find the next 7 o'clock NSDate
There's a much easier approach to this problem.

We can use NSCalendar's nextDateAfterDate:matchingComponents:options: method to find both our next 7am and 7pm.  Then it's simply a matter of comparing these values and returning the lesser of the two.

NSDate * nextSevenOClock() {
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [[NSDateComponents alloc] init];

    components.hour = 7;
    NSDate *nextSevenAm = [calendar nextDateAfterDate:[NSDate date]
                                   matchingComponents:components
                                              options:NSCalendarMatchNextTimePreservingSmallerUnits];

    components.hour = 19;
    NSDate *nextSevenPm = [calendar nextDateAfterDate:[NSDate date]
                                   matchingComponents:components
                                              options:NSCalendarMatchNextTimePreservingSmallerUnits];

    NSDate *nextSeven = nextSevenAm;
    if ([nextSeven compare:nextSevenPm] == NSOrderedDescending) {
        nextSeven = nextSevenPm;
    }

    return nextSeven;
}


Importantly, this approach with account correctly for things like daylight savings time and leap seconds, which the original solution does not.



This method is very specific however.  It would be good if we could get a bit more utility out of it.  And rather than a simple C-style function, I've expanded it properly into an NSDate category.

@implementation NSDate (NextTimeStamp)

+ (instancetype)nextTimeStampMatchingHour:(NSUInteger)hour {
    return [self nextTimeStampMatchingHour:hour minute:0 second:0];
}

+ (instancetype)nextTimeStampMatchingHour:(NSUInteger)hour minute:(NSUInteger)minute {
    return [self nextTimeStampMatchingHour:hour minute:minute second:0];
}

+ (instancetype)nextTimeStampMatchingHour:(NSUInteger)hour minute:(NSUInteger)minute second:(NSUInteger)second {
    NSUInteger morningHour = hour % 12;
    NSUInteger eveningHour = morningHour + 12;

    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSDateComponents *components = [[NSDateComponents alloc] init];

    components.minute = minute;
    components.second = second;

    components.hour = morningHour;
    NSDate *nextAM = [calendar nextDateAfterDate:[NSDate date]
                              matchingComponents:components
                                         options:NSCalendarMatchNextTimePreservingSmallerUnits];

    components.hour = eveningHour;
    NSDate *nextPM = [calendar nextDateAfterDate:[NSDate date]
                              matchingComponents:components
                                         options:NSCalendarMatchNextTimePreservingSmallerUnits];

    return [nextAM compare:nextPM] == NSOrderedAscending ? nextAM : nextPM;
}

@end


For your original exxample of looking for the next 7 o'Clock, we can just do simply:

NSDate *nextSeven = [NSDate nextTimeStampMatchingHour:7];


But with these extra methods, we can look for more specific times:

NSDate *nextSevenFifteen = [NSDate nextTimeStampMatchingHour:7
                                                      minute:15];