• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
NSMutableArray & Pointers
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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
  • Follow-Ups:
    • Re: NSMutableArray & Pointers
      • From: Jeff Gilbert <email@hidden>
    • Re: NSMutableArray & Pointers
      • From: stephane sudre <email@hidden>
    • Re: NSMutableArray & Pointers
      • From: AndrĂ©as Saudemont <email@hidden>
  • Prev by Date: Re: Looking for a sample for print header & footer
  • Next by Date: Re: NSMutableArray & Pointers
  • Previous by thread: Re: Diff between Build styles in X Code.
  • Next by thread: Re: NSMutableArray & Pointers
  • Index(es):
    • Date
    • Thread