Re: Incorrect instance of custom view loading after unarchiving
Re: Incorrect instance of custom view loading after unarchiving
- Subject: Re: Incorrect instance of custom view loading after unarchiving
- From: Sam Krishna <email@hidden>
- Date: Sat, 23 Aug 2008 10:36:16 -0400
Hi all,
Thanks to Quincey's note and some back-referencing to one of the
earlier RaiseMan projects, I was finally able to solve this.
(as usual) The solution actually was simpler than I thought. I had to
*effectively* override these two methods:
- (NSData *)dataOfType:(NSString *)typeName error:(NSError **)outError;
- (BOOL)readFromData:(NSData *)data ofType:(NSString *)typeName error:
(NSError **)outError;
I was doing *too much work* by making MyDocument conform to NSCoding.
These two methods were doing the equivalent work of NSCoding for me. I
just had to create a cleaner "object model" separation by only
archiving my NSMutableArray to store my NSBezierPaths.
This was a GINORMOUS breakthrough for me! I'd been afraid of doing
graphical programming in Cocoa *FOREVER* (almost 10 years). Now I see
how easy it is, esp. w/ all the new stuff in Leopard, and it's amazing.
Thank you all!
Live Playfully,
Sam
On Aug 23, 2008, at 12:12 AM, Quincey Morris wrote:
On Aug 22, 2008, at 20:45, Sam Krishna wrote:
OK, I've read all the email from the past month about Aaron's
challenge in Ch. 18 of Cocoa Programming. I've got a custom view
(OvalView) where the magic happens. I've got Undo working, but I
can't get the app to load a saved document b/c it keeps loading the
wrong instance of OvalView on unarchiving.
[snip]
Here's my Q: What do I need to do to fix it? Is there some simple
IB3 gestalt that I'm missing? Some NSCoding voodoo that's
completely obvious? what gives?
Well, if it was completely obvious, you wouldn't have missed it. ;)
What you're doing wrong is archiving your view (something that
*draws* an oval). What you really need to do is archive your data
model (something that *describes* an oval). That means you should
keep the oval description separate from the view, and let the view
refer to the separate description for the parameters it needs to
draw the oval.
Write on the blackboard 100 times:
MVC
MVC
MVC
...
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden