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 protected])
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 [email protected]