Re: Assigning an element of a swift array to a userdata parameter triggers didSet

2015-11-18 Thread John McCall
> On Nov 18, 2015, at 11:12 AM, Quincey Morris > wrote: > On Nov 18, 2015, at 10:57 , Jens Alfke wrote: >> >> Doesn’t the pointer become invalid as soon as myElement goes out of scope? >> (There’s a reason that type is called *Unsafe*Pointer…) > > Yes, but so does &myArray[0] in the original

Re: Assigning an element of a swift array to a userdata parameter triggers didSet

2015-11-18 Thread Charles Srstka
> On Nov 18, 2015, at 7:24 AM, Eric Gorr > 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 lif

Re: Assigning an element of a swift array to a userdata parameter triggers didSet

2015-11-18 Thread Quincey Morris
On Nov 18, 2015, at 10:57 , Jens Alfke wrote: > > Doesn’t the pointer become invalid as soon as myElement goes out of scope? > (There’s a reason that type is called *Unsafe*Pointer…) Yes, but so does &myArray[0] in the original code. According to your hypothesis, it’s copied into a temporary,

Re: Assigning an element of a swift array to a userdata parameter triggers didSet

2015-11-18 Thread Jens Alfke
> On Nov 18, 2015, at 10:17 AM, Quincey Morris > wrote: > > 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.addToolT

Re: Assigning an element of a swift array to a userdata parameter triggers didSet

2015-11-18 Thread Quincey Morris
On Nov 18, 2015, at 05:24 , Eric Gorr 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, i

Re: Assigning an element of a swift array to a userdata parameter triggers didSet

2015-11-18 Thread Eric Gorr
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 toolt

Re: Assigning an element of a swift array to a userdata parameter triggers didSet

2015-11-17 Thread Jens Alfke
I think the cause is “&(myArray[0])”. In Swift it isn't possible to get a pointer to an array item — these aren’t C arrays, their internal representation is opaque! So what I think happens is that it copies myArray[0] into a temporary and creates an UnsafeMutablePointer to that. Then, after the

Assigning an element of a swift array to a userdata parameter triggers didSet

2015-11-17 Thread Eric Gorr
I created the default Cocoa/Swift app. My AppDelegate class is below. I have hooked the view in the window to the view IBOutlet in the AppDelegate. What I am trying to do is assign a element from an array to the userdata for a tooltip. The code executes and prints 'did set' three times. I would