Search code examples
iosipadios-simulatorselectorperformselector

performSelector:withObject sending wrong object only on iPad


I call a selector on a target like this:

        target.performSelector(successAction, withObject: timeIntervalPicker.timeInterval)

Before and after this call a print out confirms that timeInterval is e.g. 90.0

The called method however receives complete garbage. Instead of 90.0 it receives something like 7.9616198705550417E+277

The received value also varies form call to call.

To make this even more confusing, this only happens on the iPad simulator. Not on the iPhone simulator.

Help is very much appreciated.


Solution

  • Create an NSNumber with the value you want to send, and convert that received NSNumber back to it's original type (double or timestamp):

    target.performSelector(successAction, withObject: NSNumber(double: timeIntervalPicker.timeInterval))