Re: Saving NSObjectController info
Re: Saving NSObjectController info
- Subject: Re: Saving NSObjectController info
- From: mmalcolm crawford <email@hidden>
- Date: Wed, 16 Feb 2005 00:42:26 -0800
On Feb 15, 2005, at 10:43 PM, <email@hidden>
<email@hidden> wrote:
First off, the Recipe object is declared in MyDocument.h (Recipe*
recipe;), but I don't want to instantiate it in MyDocument.m, that's
the ObjectController's job, right?
No -- in this case, for a single "root" object, you would typically
instantiate it in MyDocument.
So here is the method to save the object to disk:
- (void)dataRepresentationOfType:(NSString*)aType
{
return [NSArchiver archivedDataWithRootObject:recipe];
}
The method signature should be:
- (NSData *)dataRepresentationOfType:(NSString *)aType
Here is the load data method:
- (void)windowControllerDidLoadNib:(NSWindowController*)aController
Assuming this is a stanndard document-based application, the load
method should be
- (BOOL)loadDataRepresentation:(NSData *)data ofType:(NSString *)aType
See:
<http://developer.apple.com/documentation/Cocoa/Conceptual/Documents/
index.html>
{
Recipe* newRecipe = [[NSUnarchiver
unarchiveObjectWithData:fileData] retain]; // fileData is my NSData*
object
recipe = newRecipe;
[newRecipe release];
}
Now, before, instead of "recipe = newRecipe", I had my object
controller use setContent:newRecipe, and it worked fine.
You need to call a KVO-compliant accessor method for the KVO
notification to be sent so that the object controller notices your
variable has changed.
See:
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaBindings/Concepts/WhatAreBindings.html>
and
<http://developer.apple.com/documentation/Cocoa/Conceptual/
CocoaBindings/Concepts/HowDoBindingsWork.html>
analogous also to:
<http://homepage.mac.com/mmalc/CocoaExamples/controllers.html>
"Programmatic modifications to arrays not noticed by table view"
mmalc
_______________________________________________
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