My version


#1

Hi here’s my version with a controller object

#import <Cocoa/Cocoa.h>
@interface charactercountAppDelegate : NSObject
@property (assign) IBOutlet NSWindow *window;
@end

#import “charactercountAppDelegate.h”
@implementation charactercountAppDelegate
@synthesize window = _window;

  • (void)applicationDidFinishLaunching:(NSNotification *)aNotification
    {
    // Insert code here to initialize your application
    }
    @end

//the controller class

#import <Cocoa/Cocoa.h>

@interface countController : NSViewController
{

}
@property (weak) IBOutlet NSTextField *stringToCount;
@property (weak) IBOutlet NSTextField *displayedstring;

  • (IBAction)countCharacters:(id)sender;

@end

#import “countController.h”

@implementation countController
@synthesize stringToCount;
@synthesize displayedstring;

  • (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

    }

    return self;
    }

  • (IBAction)countCharacters:(id)sender
    {
    NSUInteger numberOfCharacters;

    NSString *typedString = [stringToCount stringValue];

    numberOfCharacters = [typedString length];

    NSString *stringToDisplay = [NSString stringWithFormat:@" ‘%@’, has %lu characters",typedString,numberOfCharacters];

    [displayedstring setStringValue:stringToDisplay];
    }
    @end

Cheers

Lenny


#2

It would look more beautiful with editors code tags :smiley: