Tack för hjälpen. Nu har jag aktuell timme, minut och sekund i heltalsvariabler.
#import "ClockController.h"
@implementation ClockController
-(void)awakeFromNib
{
NSTimer *clockTimer = [[NSTimer scheduledTimerWithTimeInterval:(1.0) target:self selector:@selector(clock:) userInfo:nil repeats:YES]
retain];
if(clockTimer == nil)
{
NSLog(@Faild to create NSTimer);
[NSApp terminate:nil];
}
}
-(void)clock:(NSTimer *)clockTimer
{
NSCalendarDate *now = [NSCalendarDate calendarDate];
NSString *stringDate = [[NSString alloc] initWithString:[now descriptionWithCalendarFormat:@"%H:%M:%S"]];
NSString *stringHour = [stringDate substringWithRange:NSMakeRange(0,2)];
NSString *stringMinute = [stringDate substringWithRange:NSMakeRange(3,2)];
NSString *stringSecond = [stringDate substringWithRange:NSMakeRange(6,2)];
int hour = [stringHour intValue];
int minute = [stringMinute intValue];
int second = [stringSecond intValue];
NSLog(@"%i:%i:%i", hour, minute, second);
}
@end