On Nov 18, 2015, at 05:24 , Eric Gorr <mail...@ericgorr.net> wrote:
> 
> Yes, that all makes sense. So, the question is what can I do about it? The 
> number of tooltips I need is the same number of elements in the array and the 
> number of elements in the array can change over the lifetime of the 
> application. So, it is natural to store the information needed by the tooltip 
> inside of an array and pass a pointer to an array element as the userdata for 
> the tooltip. If my current implementation is not going to work, what is the 
> recommended implementation for this kind of behavior?

If the array element (a dictionary, in your original post) is small enough, you 
can pass a pointer to a copy of the element instead of a pointer to the 
element. That is:

        var myElement = myArray[0]
        view.addToolTipRect( NSMakeRect( 0, 0, 100, 100), owner: self, 
userData: &myElement )

If you don’t want to make a copy of the element, the best approach is to make 
the array elements reference types rather than value types. (You could use 
NSDictionary, for example.) Swift makes it so easy to use value types, it’s 
hard to remember that the old Obj-C way of doing things is sometimes better.

You should probably also submit a bug report about the NSView tool tip APIs. 
There ought to be a better way in Swift than using unmanaged memory pointers. 
They have potential memory management issues for ARC, too.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to