Rixstep
 About | ACP | Buy | Industry Watch | Learning Curve | News | Search | Test
Home » Learning Curve

NCE - The OS X No Code Editor 2

All legacy text apps for all versions of MacOS are outdated. Here's why.

For these exercises you will need:
  • the ADC developers tools; and
  • ambition, patience, and perseverance.

We have very little to do to turn this project into a text editor capable of opening, editing, and saving files. We already got the editing part down without writing any code at all; the opening and saving require so little it'll make your head spin.

But first we have to make an adjustment to the project itself so our program gets its own file extension. Go into the Project menu and 'Edit Active Target NCE'. Go to the second grouping of settings called 'Info.plist Entries'. Compare with the picture below - you'll see something similar if you click on 'Document Types'.

  1. In the 'Name' field type in 'NCE Document'.

  2. In the 'Extensions' field type in 'nce'.

That's it. Now we need to make an adjustment with Interface Builder - again, this takes no code.


Find 'MyDocument.nib' in the left margin and double-click it to open the window in Interface Builder.

  1. Double-click 'File's Owner' in the main control window.

  2. Click on the 'Outlets' tab, then 'Add', and add 'textView' as an 'outlet'.

  3. Now go back to the first tab in the main control window and 'ctrl-drag' from the File's Owner icon to the text view in the window. An inspector will appear and at the top it will say 'Connections'.

  4. Make sure 'textView' is selected, then click 'Connect' in the lower right hand corner. Your inspector should now look like the second image at right.

What you've done is create an outlet - a sort of reference - to the text view that the program will know about. You've called it 'textView'. We shall be using this name a few more times.

Save the Interface Builder project and exit.

Back in the left margin of Xcode/Project Builder, click on 'MyDocument.h'. This will open the file in the editor. See that your file looks like the following.

#import <Cocoa/Cocoa.h>

@interface MyDocument : NSDocument
{
    id textString, textView;
}
@end

You've added two so-called pointers: one is 'textView' which you used in Interface Builder; the other, 'textString', will be used shortly.

Save the file and close it with ⇧⌘W.

Now click on 'MyDocument.m' to open it. Now we shall write some code - but as you shall see it's very little, and it's easy for you to copy in.

You have to adjust three 'methods'. They're given in alphabetic order here. Just make sure yours look exactly like the following. When you finish, save the file.

- (NSData *)dataRepresentationOfType:(NSString *)aType
{
    return [[textView string]
        dataUsingEncoding:NSMacOSRomanStringEncoding];
}

- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
    return ((textString =
        [[NSString alloc] initWithData:data
        encoding:NSMacOSRomanStringEncoding]) != 0);
}

- (void)windowControllerDidLoadNib:(NSWindowController *)aController
{
    [super windowControllerDidLoadNib:aController];

    if (textString) {
        [textView setString:textString];
        [textString release]; textString = 0;
    }
}


That's all: build your application and test it. You can now save files (with the extension 'nce') and you can open them and edit them - everything.

You've just written your first program, and it's a fully functional text editor, and you couldn't write a line of code (and still can't) and yet you did it in five minutes tops.


So - do you still think OS X needs text editors for $179?

About | ACP | Buy | Industry Watch | Learning Curve | News | Products | Search | Substack
Copyright © Rixstep. All rights reserved.