Permalink
Browse files

Updating with an `NSTimer`. Now it’s a clock! :D

  • Loading branch information...
ELLIOTTCABLE committed Jun 8, 2010
1 parent 928b2af commit bc40ed504237a6a8d4839dcae8995f3947aff82b
Showing with 27 additions and 6 deletions.
  1. +1 −0 YRSolcounter.h
  2. +26 −6 YRSolcounter.m
View
@@ -17,6 +17,7 @@
IBOutlet //»
NSTextField *textField;
BundleUserDefaults *defaults;
NSTimer *timer;
}
@end
View
@@ -15,19 +15,39 @@ - (id)initWithBundle:(NSBundle *)bundle
{
if ( (self = [super initWithBundle: bundle]) == nil ) return nil;
defaults = [[BundleUserDefaults alloc]
initWithPersistentDomainName: [bundle objectForInfoDictionaryKey: @"CFBundleIdentifier"]];
[defaults registerDefaults: [NSDictionary dictionaryWithContentsOfFile:
[bundle pathForResource: @"UserDefaults" ofType: @"plist"]]];
[(defaults = [[BundleUserDefaults alloc]
initWithPersistentDomainName: [bundle objectForInfoDictionaryKey: @"CFBundleIdentifier"]])
registerDefaults: [NSDictionary dictionaryWithContentsOfFile:
[bundle pathForResource: @"UserDefaults" ofType: @"plist"]]];
[[[NSNib alloc] initWithNibNamed: @"Solcounter" bundle: bundle]
instantiateNibWithOwner: self topLevelObjects: nil];
timer = [NSTimer scheduledTimerWithTimeInterval: 0.0
target: self
selector: @selector(handleTimer:)
userInfo: nil
repeats: YES];
NSNib *nib = [[NSNib alloc] initWithNibNamed: @"Solcounter" bundle: bundle];
[nib instantiateNibWithOwner: self topLevelObjects: /* sets `textField` */ nil];
[self setView: textField];
[nib dealloc];
return self;
}
- (void)handleTimer:(NSTimer *)_
{
double date = [[NSDate date] timeIntervalSince1970];
[textField setStringValue:
[NSString stringWithFormat: @"%3llu %03llu ſ %03llu %03llu %03llu",
(unsigned long long int)(date / 86400000) % 1000,
(unsigned long long int)(date / 86400) % 1000,
(unsigned long long int)(date / 86.4) % 1000,
(unsigned long long int)(date / 0.0864) % 1000,
(unsigned long long int)(date / 0.0000864) % 1000]];
}
- (void)dealloc
{
[textField release];

0 comments on commit bc40ed5

Please sign in to comment.