On Mar 13, 2009, at 12:05 AM, Graham Cox wrote:

Minor problem, I think, but I'd like to get some advice about the right way to approach this.

One of my classes can sometimes fail in -initWithCoder: - it relies on certain resources being available and if it doesn't get them, I thought I could follow the same pattern as -init and autorelease self and return nil. When I do this though I get an error from the dearchiver, like:

*** -[__NSPlaceholderDictionary initWithObjects:forKeys:]: number of objects (0) not equal to number of keys (298)

This prevents the remainder of the archive from loading, which I don't want.

What's a good way to handle this? I would prefer that my object isn't created at all if possible, but that the archive loads what it can. It's hard to handle this in the class that owns this, because it's just an array of objects.

I'm thinking I need some post-processing that goes through and weeds out certain flagged objects, but maybe there's a better way?

You could set some flag in initWithCoder: and then return nil from awakeAfterUsingCoder: when the flag is set.

Cheers,
M
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to