Swift iOS: EXC_BAD_INSTRUCTION

In my main ViewController, I have this:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)

    println("VIEW CONTROLLER DID APPEAR")

    var currentUser = PFUser.currentUser()
    println(currentUser)

    if (!currentUser) {
        self.presentLogInController()
    } else {
        println("VALID USER")
    }
}

When the application starts, this line causes an error:

if (!currentUser) {

with the message EXC_BAD_INSTRUCTION

However, the output window shows:

VIEW CONTROLLER DID APPEAR
<PFUser:TzzzzzzaHx:(null)> {
    email = "blah@blah.bla";
    username = mmm;
}
VALID USER

Given that code executing outside of the line Xcode says causes EXC_BAD_INSTRUCTION, this does not seem to be a critical error, although this leads to a failure of the simulator and the real device.

Any tips on debugging this?

FOUND SOLUTION

if let user = PFUser.currentUser() {
    println("VALID USER")
    println(user)
    println(user["email"])
    println(user["completedTour"])
    if !user["completedTour"] {
        println("NO TOUR YET")
    }
} else {
    self.presentLogInController()
}
+4
source share
2 answers

if (!currentUser)... is there currentUsera Bool? Most likely not. You cannot use non-Bool expressions in if expressions, as in Objective-C

Assuming that PFUser.currentUser()returns implicitly deployed option, you will need to check the zero.

if currentUser != nil { ... }

+3

, objective-c. PFUser.currentUser() PFUser, nil, .

var currentUser = PFUser.currentUser()

, if.

if currentUser {
    println("VALID USER")  
} else {
    self.presentLogInController()
}

currentUser if, if let. if let user = currentUser {...} , , .

0

Source: https://habr.com/ru/post/1544242/


All Articles