osx - Swift target action -


i'm coming c# background , i'm trying swift , osx development. when implement custom control in .net can create events notify event handlers of things going on in control.

for example: if create control allows user drop files on it, can fire event whenever user drops file , event handler can directly handle dropped file.

now, want implement nscontrol derived view. nscontrol implements target-action pattern , provides action action, can connect in interface builder method handle action. action action available when right-click control:

enter image description here

now want define another action (and maybe later) can connected same way using ib. looked definition of nscontrol , shows me following 2 lines:

weak public var target: anyobject?  public var action: selector 

but adding similar code subclass doesn't in ib (the @ibdesigable attribute set class).

i went on define protocol can implemented delegate:

public protocol somedelegate {     func somedelegatemethod(path: string) }  @ibdesignable public final class greatcontrol: nscontrol {     public var delegate: somedelegate? 

i can set delegate in code this:

@iboutlet weak var mygreatcontrol: greatcontrol!  override func viewdidload() {     super.viewdidload()     self.mygreatcontrol!.delegate = self } 

but i'd set delegate using ib instead of in code.

the question is: i'd prefer target-action pattern close .net or other event-driven environments do. how can implement can connect actions using ib? if that's not possible, can somehow make @ least delegate can set through ib instead of code only?


ps: when google this, there's hardly information osx. there seem ios developers out here. i'd prefer answers not detail how things ios (unless work same osx), don't develop ios app.


Comments