• 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
Re: NSNumber pointerValue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSNumber pointerValue


  • Subject: Re: NSNumber pointerValue
  • From: Ali Ozer <email@hidden>
  • Date: Thu, 20 Nov 2003 23:15:09 -0800

This "works" with the old archiver, but not keyed archiver. That seems to be because in the latter case, as a result of the archiving/unarchiving, the unarchived NSNumber has a 'q' type, which is not pointer-sized, thus leading to the 0 result.

Whether 'q' is expected in this case is something we need to look at, but in any case, as others have pointed out, creating an NSNumber with an int then extracting a pointer is risky business, and should maybe have been explicitly disallowed from day one. Extracting an int should be fine, but might indeed be problematic on some architectures. The NSData approach some have pointed out is probably the best.

Ali


Begin forwarded message:

From: Bjvrn Carlstrvm <email@hidden>
Date: November 17, 2003 13:51:50 PST
To: email@hidden
Subject: NSNumber pointerValue

I'm using this code to put a pointer into a NSNumber

NSNumber* theNumber = [NSNumber numberWithInt:(int)res];
NSLog(@"Dragging resource %@",theNumber);
Resource* theRes;
theRes = [theNumber pointerValue];

The last two lines are just a check to see if I can get the pointer back, which I can.

However, putting theNumber on the pasteboard and retrieving it after a drag operation works differently. The NSNumber contains the correct value and I can type cast it to the desired pointer, but the line:
theRes = [theNumber pointerValue];
returns nil!

My workarround looks like this.
theRes = (Resource*) [theNumber intValue];

Does anybody know why this would yield different results before and after being on the pasteboard?
_______________________________________________
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.

  • Follow-Ups:
    • Re: NSNumber pointerValue
      • From: Björn Carlström <email@hidden>
References: 
 >NSNumber pointerValue (From: Björn Carlström <email@hidden>)

  • Prev by Date: Re: I can't figure out how to use NSIndexSet
  • Next by Date: Re: Dynamically Generating GUI forms from an XML file?
  • Previous by thread: Re: NSNumber pointerValue
  • Next by thread: Re: NSNumber pointerValue
  • Index(es):
    • Date
    • Thread