Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

NSMutableArray & Pointers



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:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.