Re: NSNumber pointerValue
Re: NSNumber pointerValue
- Subject: Re: NSNumber pointerValue
- From: Björn Carlström <email@hidden>
- Date: Thu, 20 Nov 2003 07:48:41 +0100
2003-11-19 kl. 21.54 skrev Alastair Houghton:
On 19 Nov 2003, at 19:45, 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.
Why not give the strings some sort of unique identifier, and use that
instead? It's much better than placing pointers on a pasteboard, not
only because it will work, but also because it's more robust. If you
use an NSMutableDictionary (or some other hash-table-based mechanism)
to hold a mapping between unique ID and string, it will be more than
fast enough; more to the point, you will be able to tell whether or
not the value you get back from the pasteboard is valid, something
which you cannot do if you put a pointer on there.
Well, I'm not a professional at this so maybe there's something I'm
missing here. The strings are part of the user interface. The user can
import these from other documents. There is no way to make sure two
identical strings does not appear. Since the user dragges these from an
outline table he or she will be aware of the difference. But how will
my program know unless I have a pointer to the original object. Are you
suggesting my strings could hold some hidden sort of ID?
How will this be more robust? The type of the drag makes sure the drag
can only come from one possible source. I will be 100% sure what type
of object I'm getting. It also seems more object oriented to use
pointers. This way my source and my receiver doesn't have to know about
eachother. I can expand my app to allow for fragging from different
sources etc. Isn't it a better design to drag an object somewhere and
ask the receiver to take care of it any way it seems fit, instead of
converting the object to a string, having the receiver call back to the
source and ask it to translate the string to an object and then ghet
that object back.
All the best
Bjvrn
_______________________________________________
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.