Re: NSTreeController selection and Swift
Re: NSTreeController selection and Swift
- Subject: Re: NSTreeController selection and Swift
- From: Quincey Morris <email@hidden>
- Date: Tue, 24 May 2016 17:58:33 -0700
- Feedback-id: 167118m:167118agrif8a:167118sOkHm53Z1y:SMTPCORP
On May 24, 2016, at 17:49 , Rick Mann <email@hidden> wrote:
>
> I'm trying to observe an NSTreeController's selection property, and then do something with that selection when it changes. But Swift doesn't just let me treat .selection as my object type (the way Obj-C would). So, can I use it (short of calling -valueForKey:) from Swift?
’treeController.selection' is of type AnyObject, but it can be a marker object (no selection or multiple selection or …) OR one of your objects. So to get your object, use:
if let myObject = treeController.selection as? MyObject {
// do whatever if an object is selected
}
Is that what you want?
_______________________________________________
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