The problem is that I want to subclass a Combobox Control whose content is unknown and is loaded at run time by a webserver (and I also hav pther reasons to subclass controls)
I dont want to user outlets like in Eskimo solution, because I will have more than hundred window controllers in the program, with zoen of controls each, and outlets are too heavy to implemet.
So lets say that in a window Controller, I have 2 combobox controls with identifier "filter1" for the first and "filter2" for the second
By convention, I say that if a method exists to load the controls, his name will be load<Identifier of combobox>
for instance:
class myWindow: NSWindowController {
............
@objc func loadMyfilter1 (ctrl: NSCombobox) {
... do something ...
}
}
in this example, there is a method to load filter1, and no method to load filter2 (why not?)
that's why I dont't know in advance ythe name of ythe method
Now, If I iterate (in an other class, to make it harder) on the list of controls, I have somewhere in that other class:
func test (controller: NSWindowController, ctrl: NSControl) {
if ctrl is NSCombobox {
let methodName: String = "load"+ctrl.identifier.capitalized
let aMethod = Slector(methodName) // or as you say let aMethod = #selector(methodName)
if controller.responds (to: aMethod) {
controller.perform (aMethod, with: ctrl)
}
}
}
this doe'snt work because loadMyfilter1 needs a parameter
if loadMyfilter1 is declared
class myWindow: NSWindowController {
............
@objc func loadMyfilter1 () {
... do something ...
}
}
it works