objective c - NSThread detachNewThreadSelector: Crash only in release build in Xcode 7 + Swift 2.0 -
i have framework calls methods in appdelegate
using detachnewthreadselector:
of nsthread
, looks 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
var
assigned self
in appdelegate
when framework's class initialized.
the application ran without problem in debug build, crashed @ once when above called if it's in release build. (it crashed when turned off optimize in release build.)
i'm using xcode 7 beta , swift 2.0. (i knew it's beta, it's beta supports swift 2.)
edit - end use closure instead of detachnewthreadselector:
. works in both builds.
try adding respondstoselector:
check there. dirty, that. dirty believe
func bridgeselector(selector: string?, object: string?) { if let r = responder, let sel = selector r.respondstoselector(selector(sel)) { dispatch_async(dispatch_get_main_queue(), { nsthread.detachnewthreadselector( selector(sel), totarget: r, withobject: object ) }) } }
Comments
Post a Comment