• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Assigning an element of a swift array to a userdata parameter triggers didSet
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


  • Subject: Assigning an element of a swift array to a userdata parameter triggers didSet
  • From: Eric Gorr <email@hidden>
  • Date: Tue, 17 Nov 2015 18:39:07 -0500

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 have thought it would only print 'did set' twice, but the third time is when addToolTipRect is called and I pass in the first element of the array as the userdata for the tooltip rect.

This seems strange to me and I was wondering if anyone knew how I could avoid this behavior. The behavior I was looking for is for didSet to only be called when myArray was assigned to perhaps a different array entirely. Perhaps didSet is not what I want to be using...and, if not, what should it be?


@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate
{
    @IBOutlet weak var window: NSWindow!
    @IBOutlet weak var view:   NSView!

    var myArray = [[String:AnyObject]]()
    {
        didSet
        {
            NSLog( "did set" )
        }
    }

    override func view(view: NSView, stringForToolTip tag: NSToolTipTag, point: NSPoint, userData data: UnsafeMutablePointer<Void>) -> String
    {
        let pUserData = UnsafeMutablePointer<[String:AnyObject]>(data)
        let userData  = pUserData.memory

        return "hello"
    }

    func applicationDidFinishLaunching(aNotification: NSNotification)
    {
        self.myArray.append( [ "one" : "a" ] )
        self.myArray.append( [ "two" : "b" ] )

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



    func applicationWillTerminate(aNotification: NSNotification)
    {
    }
}
_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden


  • Follow-Ups:
    • Re: Assigning an element of a swift array to a userdata parameter triggers didSet
      • From: Jens Alfke <email@hidden>
  • Prev by Date: Radar down?
  • Next by Date: a question concerning how to fire a message at the beginning of my application
  • Previous by thread: Radar down?
  • Next by thread: Re: Assigning an element of a swift array to a userdata parameter triggers didSet
  • Index(es):
    • Date
    • Thread