Re: NSNumber pointerValue
Re: NSNumber pointerValue
- Subject: Re: NSNumber pointerValue
- From: Björn Carlström <email@hidden>
- Date: Thu, 20 Nov 2003 07:56:00 +0100
2003-11-19 kl. 23.02 skrev Dietmar Planitzer:
On Nov 19, 2003, at 8:45 PM, Bjvrn Carlstrvm wrote:
I'm dragging internal objects that are represented by a sting in a
list into another view. I want to create a link from the destination
to the object being dragged. My data structure requires this to be a
pointer. I looked at alternatives, draggimg the string and then after
the drag looking up the original object in a table, etc. But all the
alternatives has drawbacks and seem akward and slow.
Dragging pointers has been discussed on this messageboard before and
I believe it got the solution to convert the pointer to a NSNumber
from someone on this board. It's an elegant solution to my problem.
I'm only confused buy the behaviour of NSNumber. I think no object
should return different results before and after being placed on the
pasteboard.
Have you already tried replacing your use of NSNumber with NSValue ?
More specifically, create an NSValue instance by doing a myValue =
[NSValue valueWithPointer: myPointer] and access it via [myValue
pointerValue].
Yes, I have. The reason I use NSNumber is that I want to put several of
these into a propertyList on the pasteboard. NSValue can't do that.
Just a guess, but it may be the case that NSNumber gets confused
because at first it gets created as an integer container, then
serialized when copied to the pasteboard and then after
de-serialization you ask it for a pointer value. NSNumber and NSValue
internally store the data type of their value.
Do you know how NSNumber and NSValue store values internally? Then you
must know the answer to this! My original question was why would
NSValue return a different result after being put on the pasteboard?
Different storing might explain it. Still inconsistency seems more like
a bug then a feature.
In any case, you should never cast a pointer to an int. This works on
the current hardware and OS but is likely going to fail as soon as OS
X gets support for 64bit address spaces.
I know, it's a workarround because of the above problem. I would love
to use pointerValue and be safe in the future. Can you suggest a more
robust workarround? I'm a little relluctant to guess what NSNumber will
return in a 64 bit future, with the inconsistences above...
Regards,
Dietmar Planitzer
_______________________________________________
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.