开发者

Trigger on scheduled events

I got an schedule in an plist-file, reading the events (read: times) is not the problem. The pr开发者_JAVA百科oblem is comparing the events with the current time. I am somewhat new to iPhone-development so it might be an easy answer for this but here it goes: scheduleTime isEqualToString currentTime - well that does the trick almost... What I need is: if(scheduleTime>currentTime && scheduleTime

Is the best thing 10 if after each other or should I use something else? switch?

TIA for all you answer me!


Use

- (NSComparisonResult)compare:(NSDate *)anotherDate

for any NSDate objects. It will return a NSComparisonResult.

enum {
  NSOrderedAscending = -1,
  NSOrderedSame,
  NSOrderedDescending
};
typedef NSInteger NSComparisonResult;


Time to give something back... here is my end result of my own question thanks to Paul I solved it.

NSDateFormatter *formattedTime = [[NSDateFormatter alloc] init];
[formattedTime setDateFormat:@"HH:mm"];

NSDate *now = [[NSDate alloc] init];

NSString *currentTime = [formattedTime stringFromDate:now];
NSString *scheduledTime = @"12:00";

[formattedTime release];
[now release];

NSComparisonResult result = [currentTime compare:scheduledTime];

switch (result)
{
    case NSOrderedAscending: NSLog(@"%@ is before %@", currentTime, scheduledTime); break;
    case NSOrderedDescending: NSLog(@"%@ is after %@", currentTime, scheduledTime); break;
    case NSOrderedSame: NSLog(@"%@ is same %@", currentTime, scheduledTime); break;
    default: NSLog(@"erorr dates %@, %@", currentTime, scheduledTime); break;
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜