Skip to content

Instantly share code, notes, and snippets.

@vincentlg
Created May 27, 2011 17:24
Show Gist options
  • Save vincentlg/995727 to your computer and use it in GitHub Desktop.
Save vincentlg/995727 to your computer and use it in GitHub Desktop.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
window = [[UIWindow alloc] initWithFrame:[ [UIScreen mainScreen] bounds]];
[window makeKeyAndVisible];
//init du modèle
model = [ClockModel new];
//init de la vue
ClockView *view = [[ClockView alloc]initWithFrame:CGRectMake(10, 30,360.0, 20.0)];
view.controller=self;
//Ajout de la vue clockView
[window addSubview:view];
[view release];
//init controlleur (call pendulumSwing chaque seconde)
self.pendulum = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(pendulumSwing:) userInfo:nil repeats:YES];
return YES;
}
-(void)pendulumSwing:(NSTimer*)theTimer //Met à jour les propriétés de l'objet clockModel à chaque seconde
{
NSDateComponents *comp = [[NSCalendar currentCalendar]components:(NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit)fromDate:[NSDate date]];
[self setValue:[NSNumber numberWithInt:[comp hour]] forKeyPath:@"model.hour"];
[self setValue:[NSNumber numberWithInt:[comp minute]] forKeyPath:@"model.minute"];
[self setValue:[NSNumber numberWithInt:[comp second]] forKeyPath:@"model.second"];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment