title: How to perform a selector on the main thread with the AppDelegate in a global function, in swift?
body: <p>I want the AppDelegate to perform the selector if it is possible, here is my code:</p>
  
  <pre><code>func RunLoopSourceScheduleRoutine(info:UnsafeMutableRawPointer?,r1:CFRunLoop?,mode:CFRunLoopMode?)-&gt;Void{
  
      let obj :  RunLoopSource = Unmanaged&lt;RunLoopSource&gt;.fromOpaque(info!).takeUnretainedValue()
      let theContext = RunLoopContext.init(initWithSource: obj, andLoop: r1!)
  
      let del = UIApplication.shared.delegate
  
      del.performSelector(onMainThread: #selector(removeSource), with: theContext, waitUntilDone: false)
  
  }  
  </code></pre>
  
  <p>I've tried this :(The App crashes)  </p>
  
  <pre><code> AppDelegate.performSelector(onMainThread: #selector(removeSource), with: theContext, waitUntilDone: false)
  </code></pre>
  
  <p>How to perform a selector on the main thread from a global function?</p>