I am trying to learn Swift -- current task is making a simple menu for a Mac app from an array of objects that contain strings. The problem now is how to pass the selector, which in the array is a string, but in the code is a function.
The class is
class menuArrayObject
{
var title: String = ""
var subMenuTitles: [String] = []
var subMenuSelectors: [String] = []
}
Here is my code
for index2 in 0...counter2 - 1
{
let subMenuTitle = arrayObject.subMenuTitles[index2]
let subMenuSelector = NSSelectorFromString(arrayObject.subMenuSelectors[index2])
let subMenu = NSMenuItem(title: subMenuTitle, action: #selector(subMenuSelector(_:)),keyEquivalent: "")
indexMenu.addItem(subMenu)
}
The error message (on let subMenu =) is: "argument of #selector cannot refer to a property"
Is this do-able? Is this desirable to actually do? Is there a better way?
Thanks in advanceemphasized text