SOLVED:Re: Weird coder problem
SOLVED:Re: Weird coder problem
- Subject: SOLVED:Re: Weird coder problem
- From: Joseph Jones <email@hidden>
- Date: Mon, 25 Nov 2002 15:03:46 -0800
Why is it always the blindingly obvious that is so easily missed? I forgot
to return self from initWithCoder. Urgh!
Joe
>
From: Vince DeMarco <email@hidden>
>
Date: Mon, 25 Nov 2002 14:33:48 -0800
>
To: Joseph Jones <email@hidden>
>
Cc: Cocoa Dev <email@hidden>
>
Subject: Re: Weird coder problem
>
>
How about calling super in the coding methods.
>
>
>
On Monday, November 25, 2002, at 12:01 PM, Joseph Jones wrote:
>
>
> OK, I can't seem to figure out why my items are archiving correctly,
>
> but
>
> blowing up on unarchiving. There seems to be a problem with
>
> unarchiving the
>
> array in my class, but the call stack is blowing up in the libraries
>
> and not
>
> my code, which makes it a little difficult to debug. Could anyone here
>
> provide an insight? I will append a cut down version of my code here:
>
>
>
> __________________________________________________________
>
>
>
> /* ProjectItem */
>
>
>
> #import <Cocoa/Cocoa.h>
>
>
>
> @interface ProjectItem : NSObject <NSCoding>
>
> {
>
> //Item Data
>
> NSString* _title;
>
>
>
> //Children
>
> NSMutableArray* _children;
>
> }
>
>
>
> - (id) init;
>
> - (void) dealloc;
>
> - (int) numChildren;
>
> - (ProjectItem*) childAtIndex:(int)index;
>
> - (void) addChild:(NSString*)title;
>
>
>
> - (NSString*) title;
>
> - (void) setTitle:(NSString*)aTitle;
>
>
>
> - (id) initWithCoder: (NSCoder*) decoder;
>
> - (void)encodeWithCoder: (NSCoder*) encoder;
>
>
>
> @end
>
>
>
> @implementation ProjectItem
>
>
>
> - (id) init
>
> {
>
> self = [super init];
>
>
>
> if ( self )
>
> {
>
> _children = [[NSMutableArray alloc] init];
>
> _title = @"";
>
> }
>
>
>
> return self;
>
> }
>
>
>
> - (void) dealloc
>
> {
>
> [_children release];
>
> [_title release];
>
> [super dealloc];
>
> }
>
>
>
> - (int) numChildren
>
> {
>
> return [_children count];
>
> }
>
>
>
> - (ProjectItem*) childAtIndex:(int)index
>
> {
>
> return [_children objectAtIndex:index];
>
> }
>
>
>
> - (void) addChild:(NSString*)title
>
> {
>
> ProjectItem* item = [[ProjectItem alloc] init];
>
> [item setTitle:title];
>
> [_children addObject:item];
>
> }
>
>
>
> - (NSString*) title
>
> {
>
> return _title;
>
> }
>
>
>
> - (void) setTitle:(NSString*)aTitle
>
> {
>
> [aTitle retain];
>
> [_title release];
>
> _title = aTitle;
>
> }
>
>
>
> - (void) encodeWithCoder: (NSCoder*) coder
>
> {
>
> if ( [coder allowsKeyedCoding] )
>
> {
>
> [coder encodeObject:_title forKey:@"title"];
>
> [coder encodeObject:_children forKey:@"children"];
>
> }
>
> else
>
> {
>
> [coder encodeObject:_title];
>
> [coder encodeObject:_children];
>
> }
>
> }
>
>
>
> - (id) initWithCoder:(NSCoder*) coder
>
> {
>
> self = [super init];
>
> if ( self )
>
> {
>
> if ( [coder allowsKeyedCoding] )
>
> {
>
> _title = [[coder decodeObjectForKey:@"title"] retain];
>
> _children = [[coder decodeObjectForKey:@"children"]
>
> retain];
>
> }
>
> else
>
> {
>
> _title = [[coder decodeObject] retain];
>
> _children = [[coder decodeObject] retain];
>
> }
>
> }
>
> }
>
>
>
> @end
>
> _______________________________________________
>
> cocoa-dev mailing list | email@hidden
>
> Help/Unsubscribe/Archives:
>
> http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
> Do not post admin requests to the list. They will be ignored.
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.