Carlo Di Domenico Carlo Di Domenico - 9 months ago 55
Swift Question

SWRevealViewController segue get stuck only with 1 button

I've created an app in which I need to log-in in 2 ways:
- Facebook Login,
- Normal Login (email, password).

I've added FBLogin with Facebook SDK and modified a button in order to not use fb default button. I've added a segue (Present Modally) from my loginView to anotherView with a segue (called "fb_login") and set segue class to "SWRevealViewControllerSeguePushController".

Now, I've do the same thing with my LogIn button. changed identifier and set segue class, but when i push it my app get stuck (with no error on xCode) so I need to close it and reopen it.

I've tried to change segue type from "Preset Modally" to "reveal view Controller set controller", but nothing changed (it don't get stuck, but it doesn't work).

This is the function on Login button pressed:

@IBAction func loginButtonPressed(_ sender: UIButton) {
var email = emailTextField.text
var password = passwordTextField.text
let urlString = "..."

let urlwithPercentEscapes = urlString.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)

let url = URL(string: urlwithPercentEscapes!)
URLSession.shared.dataTask(with:url!, completionHandler: {(data, response, error) in
if error != nil {
} else {
do {
let parsedData = try JSONSerialization.jsonObject(with: data!, options: .allowFragments) as! NSDictionary
let temp = parsedData["user"] as! NSArray
var userLogin = temp[0] as! NSDictionary
if((userLogin["login"]) as! Int == 1){ //login successfully = userLogin["name"]! as! String
self.user.surname = userLogin["surname"]! as! String = userLogin["email"]! as! String
self.user.url_image = userLogin["profile_img_url"]! as! String
self.user.id_user = Int(userLogin["id_user"]! as! String)!
self.user.gender = Int(userLogin["gender"]! as! String)!
self.user.birthday = userLogin["birthday"]! as! String
self.user.id_license = userLogin["id_license"]! as! String
self.user.registration_date = userLogin["registration_date"]! as! String
self.user.expire_date = userLogin["expire_date"]! as! String
self.user.mac_address = userLogin["mac_address"]! as! String
self.user.license_key = userLogin["license_key"]! as! String
self.user.license_type = Int(userLogin["license_type"]! as! String)!
self.performSegue(withIdentifier: "normal_login", sender: nil)
}else{ //login failed
print("login failed")

} catch let error as NSError {


thank you all guys! (I'm using Swift 3.0)

Answer Source

The issue is happening because you are trying to manipulate the UI from a background thread. You should always do UI related manipulations on Main thread only.

Try with:

    self.performSegue(withIdentifier: "normal_login", sender: nil)