[Assuming your code is not crashing but just won't work]
At least one problem:
self.performSegueWithIdentifier("Test", sender: self)
it should be:
dispatch_async(dispatch_get_main_queue()) { [unowned self] in self.performSegueWithIdentifier("Test", sender: self) }
Remember that all user interface operations must be performed in the main thread queue. You can prove that you are in the wrong thread by checking:
NSThread.isMainThread()
ADDITION
If any chance of self
can become null, for example, dismissal or another release because it is not needed, you should fix yourself weakly as [weak self]
not unowned
and use safe unpacking: if let s = self { s.doStuff() }
or optional chain: self?.doStuff(...)
APPENDIX 2
This seems to be a popular answer, so it's important to mention this newer alternative here:
NSOperationQueue.mainQueue().addOperationWithBlock { [weak self] in self?.performSegueWithIdentifier("Test", sender: self) }
Please note: https://www.raywenderlich.com/76341/use-nsoperation-nsoperationqueue-swift :
NSOperation vs. Grand Central Dispatch (GCD)
GCD [dispatch_ * calls] is a lightweight way of representing the units of work that will be executed simultaneously.
NSOperation adds a bit of extra overhead compared to GCD, but you can add dependency between different operations and reuse, cancel or pause them.
APPENDIX 3
Apple hides a single-threaded rule:
Note
For the most part, use UIKit classes only from the main application stream. This is especially true for classes derived from UIResponder, or that involve controlling the user interface of applications in any way.
Link:
https://developer.apple.com/documentation/uikit