As a newbie in Objective-C (I'm coming from a Java background), I am trying to build a simple screen saver that displays text.

As far as it goes (that is, using examples from the internet as my education source), it works, but when trying to go back and do things (in my mind) the right way, I'm having some trouble. It's quite possible that my issues stem from a basic misunderstanding of the Objective-C paradigm, but I'm a bit puzzled, so I thank you all in advance.

Working code:

NSPoint point; NSString *string; NSFont *font; NSColor *fontColor; NSDictionary *dictionary; … - (void)startAnimation { string = @"Hello, World!"; point = NSMakePoint(500, 500); [super startAnimation]; } … - (void)drawRect:(NSRect)rect { [super drawRect:rect]; font = [NSFont fontWithName:@"Verdana" size:18]; fontColor = [NSColor whiteColor]; dictionary = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, [NSNumber numberWithFloat:1], NSBaselineOffsetAttributeName, fontColor, NSForegroundColorAttributeName, nil]; [string drawAtPoint:point withAttributes:dictionary]; } …

Broken code:

… - (void)startAnimation { string = @"Hello, World!"; point = NSMakePoint(500, 500); font = [NSFont fontWithName:@"Verdana" size:18]; [super startAnimation]; } … - (void)drawRect:(NSRect)rect { [super drawRect:rect]; fontColor = [NSColor whiteColor]; dictionary = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, [NSNumber numberWithFloat:1], NSBaselineOffsetAttributeName, fontColor, NSForegroundColorAttributeName, nil]; [string drawAtPoint:point withAttributes:dictionary]; } …

Thank you very kindly in advance for your help!