How do you delegate the application? In Xcode 2.5 the Interface Builder has
no object named NSApplication in the Instances tab. Apparently the icon “File’s
Owner” is the same as your application. Delegate that object to your controller
and implement any of the NSApplication delegate methods.
Archiving:
Your object must implement the NSCoding protocol to be archivable. All you have
to do is something like this:
|
file.h
#import < Foundation/NSCoder.h > @interface FTModel : NSObject < NSCoding > { @public int myInt; NSString *myWord; } -(void) encodeWithCoder:(NSCoder *) coder; -(id) initWithCoder:(NSCoder *) coder; @end
|
file.m
@implementation FTModel -(void) encodeWithCoder:(NSCoder *) coder { [coder encodeInt:myInt forKey:@"favNum"]; [coder encodeObject:myWord forKey:@"favWord"]; } -(id) initWithCoder:(NSCoder *) coder { if(self=[super init]) { myNum = [coder decodeIntForKey:@"favNum"] ; //You have to retain this obj or you are in trouble myWord = [[coder decodeObjectForKey:@"favWord"] retain]; } return self; } @end
|
And in the place where you are going to archive the FTModel object:
FTModel *ftModel;
.
.
.
//archive object to file
[NSKeyedArchiver archiveRootObject:ftModel toFile:fileName];
//read the object
ftModel= [[NSKeyedUnarchiver unarchiveObjectWithFile:fileName] retain];
Once you implement the NSCode protocol the above calls to NSKeyedArchiver just
work.