Suppose I wanted to invoke a selector calc
on a specific thread. Meaning it's the case where I really must use a run loop (can't use GCD).
calc
performs some calculation and produces a result value, suppose an Int.
It is easy to pass a parameter to the selector method.
What would be a good way to retrieve the result value?
@objc function calc(val: Any) {
guard let val = val as? Int else { return }
let result = val * 10
...
}
// ... somewhere in a calling object
let val = 3
perform(#selector(MyClass.calc(val:)), on: myThread, with: val, waitUntilDone: true, modes: [RunLoopMode.commonModes.rawValue])
// ... how to get the result of calc() ?