|
Thanks for the articles. They have helped alot, but...
I've done everything to make an application that will save and load. When I compile I get five errors. They all say:
parse error before '{' token
Heres the code:
-------------------------------
//
// MyDocument.m
// SimpleTextEditer
//
// Created by Brian Allred on Mon Sep 13 2004.
// Copyright (c) 2004 __MyCompanyName__. All rights reserved.
//
#import "MyDocument.h"
@implementation MyDocument
- (id)init
{self = [super init];
if (self) {
// Add your subclass-specific initialization here.
// If an error occurs here, send a [self release] message and return nil.
}
return self;
}
- (NSString *)windowNibName
{return @"MyDocument";
}
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
if ( fileData != nil ) {
[textView replaceCharactersInRange:NSMakeRange(0, 0) withRTFD:fileData];
}
}
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSRange range = NSMakeRange(0, [[textView textStorage] length]);
return [textView RTFDFromRange:range];
}
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
fileData = data;
return fileData != nil;
}
@end
------------------
|
I am using Xcode 1.1 in OS X 10.3.5, and I had nearly the same problem. After attempting to build & run, I got one
error: parse error before "NSData"
followed by four
error: parse error before '{' token.
When I double-clicked on the first error message, it took me to MyDocument.h. After comparing this to some of the files in FoundationFramework/Headers (such as NSBundle.h), I saw that all the variable declarations in the pre-made files ended in semicolons. Unfortunately, this was not made clear in the article. The code in MyDocument.hshould look something like this:
#import <Cocoa/Cocoa.h>
@interface MyDocument : NSDocument
{id IBOutlet textView;
NSData *fileData;
}
@end
After adding the semicolons, my code compiled with no problems. I composed, saved, and re-opened this message in the resulting program.