Re: Really struggling with Saving in NSDocument
Re: Really struggling with Saving in NSDocument
- Subject: Re: Really struggling with Saving in NSDocument
- From: SA Dev <email@hidden>
- Date: Tue, 26 Jul 2005 06:56:16 -0400
Ian:
You'll want to read into the NSCoding protocol's documentation.
Any classes you try to code with NSCoder must implement the NSCoding
protocol. NSBezierPaths are compliant, so that's not the problem
there, but that may apply to your other objects as well. Just a heads-
up.
The problem you're running into is most likely the 'saving
everything as the linePath key' issue. It's not entirely clear what
contains what from your post (you may need to clarify), but if you're
saving multiple *anything*, you should throw them in an array, then
store the *array* as something like "linePaths" (note the plural
form). Each time you say [someDictionary setObject:someObject
forKey:@"theSameKeyEachTime"], you're replacing what was already
stored as theSameKeyEachTime with the new 'someObject'.
I hope this helps. If this isn't what you're talking about, please
provide a detailed description of your objects and how you're storing
them.
On Jul 26, 2005, at 5:37 AM, Ian Jackson wrote:
Hi All,
How's it going? I've been battling away for weeks now, trying to
save a NSMutableArray of my objects (graphic). The useful part of
my graphic class is an NSBezierPath.
The array is owned by MyDocument, and my graphic objects are
created in a class I wrote, which just creates the objects and puts
them in the array (it does this in response to mouse clicks in the
view) (supposed to be the controller). So I did the keyed archiving
for the paths in my graphic objects, and the Tiger style saving
method in MyDocument. It appears to save fine, but when I open the
file that's created, the paths are no longer paths. The debugger
shows that the path has crazy numbers associated with the bounds
and origin etc. I wish I had a specific question as to where this
was going wrong, but I really don't know where the problem lies.
Here are a few things I don't yet grasp:
at the momement all the paths are encoded with the same key name.
[coder encodeObject: [self linePath] forKey:@"thePath"];
If this is wrong, I'm not sure how to go about making new names for
every path (one path per graphic object).
Secondly, I don't encode my actual graphic objects anywhere, and
I'm not sure where I'd do that if it's necessary. In MyDocument?
How does the decoder know to go though the array and decode all the
paths? The array does appear to have the right amount of objects in
it when it is decoded, and it says they are of the class
corresponding to the graphic instances. I would so love to be able
to save these lines, and open them again, and get on with doing the
program I want to create!
Thanks in advance,
Ian.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40silentalcove.net
This email sent to email@hidden
_______________________________________________
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