NSMutableArray & Pointers
NSMutableArray & Pointers
- Subject: NSMutableArray & Pointers
- From: Michael Becker <email@hidden>
- Date: Thu, 21 Oct 2004 14:44:53 +0200
Hi!
I'm running into the following problem and don't know how to get around it: I have an NSMutableArray that holds NSImages. Then I specify a pointer of type NSImage* which points to an object in the array. When that object is removed from the array, I would like to be able to check whether the pointer still points to a valid NSImage. Here's a piece of code:
NSMutableArray *array = [[ NSMutableArray alloc] init];
NSImage *image = [[ NSImage alloc] initWithContentsOfFile:@"/Users/michael/Pictures/anyPicture.jpg"];
[ array addObject:image];
[ image release];
NSImage *pointer = [ array objectAtIndex:0];
NSLog(@"Pointer: %@", pointer);
[ array removeObjectAtIndex:0];
NSLog(@"Pointer: %@", pointer);
The output is:
2004-10-21 14:42:23.575 PointerTest[2345] Pointer: NSImage 0x331f80 Size={108, 144} Reps=(
NSBitmapImageRep 0x33d880 Size={108, 144} ColorSpace=NSCalibratedRGBColorSpace BPS=8 Pixels=450x600 Alpha=NO
)
2004-10-21 14:42:23.575 PointerTest[2345] Pointer: Pointer:
What is happening to the pointer-Variable?? As soon as I try to invoke [ pointer size] in the last line of my code, the app crashes. Is there any way to be able to reasonably perform an "if (pointer==nil)" statement?
Regards,
Michael _______________________________________________
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