Re: Question about Saving a document
Re: Question about Saving a document
- Subject: Re: Question about Saving a document
- From: Francis Derive <email@hidden>
- Date: Mon, 5 Jun 2006 16:16:21 +0200
Paul,
Now, I have no longer an error panel saying it was not possible to
save the document : it "saves" without notice.
But when opening the document, the NSTextField isn't filled with its
"saved" content.
Editing the "saved" content shows something like
typedstreamÅËÑ@Ö
which is the same rubbish content from the previous saves.
On Jun 5, 2006, at 12:50 PM, Paul Lynch wrote:
On 5 Jun 2006, at 11:42, Francis Derive wrote:
My document nib has :
- an instance of a simple model object,
You don't want to have your model instantiated in the nib, in general,
My model is quite closed to the Converter model object of Apple's
Documentation Cocoa Bindings Tutorial - a specialized converter, we
could say it is the Cocoa Bindings Tutorial Converter object.
So it is there, in the document nib file, with bindings to its
controller object, as there are bindings between the controller
object and the interface NSTextField.
Create an instance variable in your document subclass and set it to
the model object. Then you can access it in the dataOfType:/
readFromData: methods.
Paul
This is the document subclass :
#import <Cocoa/Cocoa.h>
#import "AToNconverter.h"
@interface MyDocument : NSDocument {
AtoNconverter *decodedObject;
}
- (void) setDecodedObject:(AtoNconverter *) theThing;
- (AtoNconverter *) decodedObject;
@end
I have overwritten :
- (NSData *) dataOfType:(NSString *)typeName error:(NSError **)
outError {
return [NSArchiver archivedDataWithRootObject:[self
valueForKey:@"decodedObject"]];
}
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName
error:(NSError **)outError {
[self setValue:[NSUnarchiver unarchiveObjectWithData:data]
forKey:@"decodedObject"];
return YES;
}
And this is the model subclass :
@interface AtoNconverter : NSObject <NSCoding> { // I notice for
myself the NSCoding protocol
NSString * asciiToConvert;
}
- (NSString *) translatedAddress;
- (NSString *) asciiToConvert;
- (void) setAsciiToConvert:(NSString *) newAscii;
@end
I have overwritten :
- (id) initWithCoder:(NSCoder *) coder
- (void) encodeWithCoder:(NSCoder *)coder {
if ([coder allowsKeyedCoding]) {
[coder encodeObject:asciiToConvert forKey:@"asciiToConvert"];
} else {
[coder encodeObject:asciiToConvert];
}
}
A long way to be the great Cocoa scholar !
Encore merci.
Francis _______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden