[:en]Swift: Assertion failure in[:]

[:en]Error message:

Assertion failure in -[UIKeyboardTaskQueue waitUntilAllTasksAreFinished], /SourceCache/UIKit_Sim/UIKit-3318.16.14/Keyboard/UIKeyboardTaskQueue.m:374 2014-11-15 17:41:29.540 Wavesss[8462:846477] *** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘-[UIKeyboardTaskQueue waitUntilAllTasksAreFinished] may only be called from the main thread.’

Use NSOperationQueue.mainQueue().addOperationWithBlock to solve the issue:


// go to Menu Screen
    func Gotomenuscreen() {
            NSOperationQueue.mainQueue().addOperationWithBlock {
                let userlevel = NSUserDefaults.standardUserDefaults().stringForKey("level")!.stringByReplacingOccurrencesOfString(" ", withString: "");
                
                if userlevel == "all" {
                    let nextViewController = self.storyboard?.instantiateViewControllerWithIdentifier("mainmenu") as! MainMenuViewController
                    self.presentViewController(nextViewController, animated:true, completion:nil)
                }
                else if userlevel == "admin" {
                    let nextViewController = self.storyboard?.instantiateViewControllerWithIdentifier("mainmenu") as! MainMenuViewController
                    self.presentViewController(nextViewController, animated:true, completion:nil)
                }
                    
                else if userlevel == "teacher" {
                    let nextViewController = self.storyboard?.instantiateViewControllerWithIdentifier("mainmenu") as! MainMenuViewController
                    self.presentViewController(nextViewController, animated:true, completion:nil)
                }
                else {
                    let nextViewController = self.storyboard?.instantiateViewControllerWithIdentifier("Menu") as! MenuViewController
                    self.presentViewController(nextViewController, animated:true, completion:nil)
                }
        }
    }


[:]

Print Friendly, PDF & Email
Scroll to Top