Save in a NSDocument-NSWindowController context
Save in a NSDocument-NSWindowController context
- Subject: Save in a NSDocument-NSWindowController context
- From: email@hidden
- Date: Tue, 11 Jul 2006 10:43:05 +0200 (CEST)
- Importance: Normal
Hello all,
recently I modified one of my Cocoa projects, replacing
a NSDocument-View pattern with a
NSDocument-NSWindowController-View pattern. The new app
works for the most part, except that, contrary to the old
app, it doesn't save correctly
(when a saved document is re-opened after being closed
it is empty).
The old project had a MyDocument class like this
@interface MyDocument : NSDocument {
IBOutlet NSTextView *textView;
NSAttributedString *myString;
}
(...)
(the app is a text editor and myString is supposed to hold
the whole text).
In the new project there is an additional class TextController
(which is a subclass of NSWindowController) and MyDocument.h
begins like this :
@interface MyDocument : NSDocument {
TextController *textController;
NSAttributedString *myString;
}
(...)
The saving methods are (almost) exactly the same in both projects :
MyDocument.m contains the following code :
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
{
NSAttributedString *tempString = [NSUnarchiver
unarchiveObjectWithData: data];
[self setString:tempString]; /*sets myString equal to tempString */
return YES;
}
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
[self setString:[************ textStorage]];
NSData* data = [NSArchiver archivedDataWithRootObject:[self string]];
return data;
}
where the row of stars is "textView" in the old project, and
"[textController textView]" in the new project. So what am I doing
wrong ?
Ewan
_______________________________________________
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