I'm using code to assign actions to my buttons when they're created. The following code DOES work without any problem:
button.addTarget(self, action: didTapDot, forControlEvents: .TouchUpInside)
button is the button object, and didTapDot is a name of a function in the same class, and that function is activated when the button is touched, so dot sign could be written on screen.
Now i'm trying to make a general code that could make later in single lines of code all the buttons which operate in very similar way. I made a function called didTap(content). Now in the same line as before, I want to replace the specific didTapDot into didTap(content).
let tapAction = "didTap("+content+")"
let tapActionSelector = NSSelectorFromString(tapAction)
button.addTarget(self, action: tapActionSelector, forControlEvents: .TouchUpInside)
I did so in the most "long and safe" way to avoid problems. the "action: " requires a NSSelector, so in order to make it I first made a String of the function I would like to send, then I turned it into NSSelector.
Now, Xcode shows still 0 errors and 0 warnings. I run the simulator. The keyboard successfully shows up. I tap on one of the created buttons - crash. I have no idea what's done wrong here :(
for the record, here's the error the console gives me after the crash:
2014-10-11 14:42:43.315 AppName[7634:561153] plugin gilad.AppName.Extension interrupted 2014-10-11 14:42:44.414 AppName[7634:561075] viewServiceDidTerminateWithError:: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "The operation couldn’t be completed. (_UIViewServiceInterfaceErrorDomain error 3.)" UserInfo=0x7f900ad206b0 {Message=Service Connection Interrupted}
So, any ideas what could have gone wrong?