Re: NSNumber pointerValue
Re: NSNumber pointerValue
- Subject: Re: NSNumber pointerValue
- From: Björn Carlström <email@hidden>
- Date: Fri, 21 Nov 2003 09:23:48 +0100
Thank you for letting me know. I will implement the NSData aproach.
Is there a reason why there isn't a +NumberWithPointer constructor for
NSNumber? Is this something that we could see in the future?
many thanks
Bjvrn
2003-11-21 kl. 08.15 skrev Ali Ozer:
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.
_______________________________________________
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.