Re: Array Problems
Re: Array Problems
- Subject: Re: Array Problems
- From: David Rocamora <email@hidden>
- Date: Sun, 10 Apr 2005 16:03:07 -0400
This is the code that has a full array in it.
- (void)createNewArtwork
{
Artwork *newArtwork = [[Artwork alloc] init];
[artworks addObject:newArtwork];
[newArtwork release];
NSLog(@"artworks is: %@", artworks);
}
When createNewArtwork adds a third object to the array NSLog says this:
artworks is: <CFArray 0x3524a0 [0xa01900e0]>{type = mutable-small,
count = 3, values = (
0 : <Artwork: 0x3524b0>
1 : <Artwork: 0x3b4d40>
2 : <Artwork: 0x3b46d0>
)}
Here is the part that returns NSData of the archived object and it's data:
- (NSData *)dataRepresentationOfType:(NSString *)aType
{
NSLog(@"artworks: %@", artworks);
return [NSArchiver archivedDataWithRootObject:artworks];
}
Here is what NSLog says with the very same array as before when this
method is run:
artworks: <CFArray 0x3029b0 [0xa01900e0]>{type = mutable-small, count
= 1, values = (
0 : <Artwork: 0x330ab0>
)}
Looking closely at this now I notice that the addresses to the two
arrays show that they are actually two different arrays. The init
method appears to be creating two different arrays. I do not know why
this is happening. Here is the init code:
- (id)init
{
if ( self = [super init]) {
artworks = [[NSMutableArray alloc] init];
activeSet = artworks;
[self createNewArtwork];
}
}
It seems to be running init twice. Why is this happening? Is there a
way to design around this?
Thanks again!
Dave
On Apr 10, 2005 2:30 PM, Serge Meynard <email@hidden> wrote:
>
> It might help if you posted the significant sections of your code...
> How are you doing the load and save exactly?
>
> By the way, you should probably be using NSKeyedArchiver instead of
> NSArchiver.
>
> _______________________________________________
> 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
>
_______________________________________________
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