• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question about Saving a document
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Follow-Ups:
    • Re: Question about Saving a document
      • From: Paul Lynch <email@hidden>
References: 
 >Question about Saving a document (From: Francis Derive <email@hidden>)
 >Re: Question about Saving a document (From: Paul Lynch <email@hidden>)

  • Prev by Date: Re: Drag & Drop iTunes Playlists
  • Next by Date: Getting correct file extension
  • Previous by thread: Re: Question about Saving a document
  • Next by thread: Re: Question about Saving a document
  • Index(es):
    • Date
    • Thread