I have a framework that calls back methods in the AppDelegate
using detachNewThreadSelector:
of NSThread
, which looks something like this:
private func bridgeSelector(selector: String?, object: String?) {
if selector != nil && responder != nil {
dispatch_async(dispatch_get_main_queue(), {
NSThread.detachNewThreadSelector(Selector(
selector!),
toTarget: self.responder!,
withObject: object
)
})
}
}
The responder
is a var
assigned to self
in AppDelegate
when the framework's class was initialized.
The application ran without problem in the debug build, but crashed at once when the above is called if it's in release build. (It also crashed when I turned off optimize in the release build.)
I'm using Xcode 7 beta and Swift 2.0. (I knew it's beta, but it's the only beta supports Swift 2.)
EDIT - I end up use closure instead of the detachNewThreadSelector:
. Works in both builds.
The solution I use to replace the above one is using
Closure
.In the class of the framework, I declared a closure variable:
Then in the main class:
When
callMeMaybe:
is called, console should printFrom Russia, with love.