Shortest Solution for Challenge Question


.h file

@interface myClass : NSObject { IBOutlet NSTextField *textField; IBOutlet NSTextField *labelField; } -(IBAction)setString:(id)sender; @end

.m file

-(IBAction)setString:(id)sender { NSUInteger len = [[textField stringValue] length]; NSString *str1 = [NSString stringWithFormat:@"%d",len]; [labelField setStringValue:str1]; }


Thats all it takes?

Why was I killing myself to allocate and initialize if I didn’t need to?

Why do I not need to do those things?




You can actually do the .m as a one liner (with similar declarations in the .h). I don’t know if there are any inherent problems with this method as I am only up to this chapter.