Reputation: 25
Im trying to check if there is a user and if they have verified their account (by phone number) and if there is and they have then let them continue but if there is a user that has not verified their phone number segue them to verify their phone number. My problem is that i set "phoneNumberVerified" in the Parse User class as a Bool but then I try to check using an if statement I get the error: Binary operator '==' cannot be applied to operands of type 'AnyObject!' and 'Bool'
Code to check user and verification status:
override func viewDidLoad() {
super.viewDidLoad()
var currentUser = PFUser.currentUser()
if currentUser == nil || currentUser!["phoneNumberVerified"] == nil {
performSegueWithIdentifier("showInitialView", sender: self)
} else {
if let numberIsVerified = currentUser!["phoneNumberVerified"] as? Bool {
if currentUser != nil && numberIsVerified == false {
performSegueWithIdentifier("showVerifyUserView", sender: self)
} else if currentUser != nil && numberIsVerified == true {
performSegueWithIdentifier("showMyPostsView", sender: self)
} else {
performSegueWithIdentifier("showInitialView", sender: self)
}
}
}
}
}
Upvotes: 0
Views: 99
Reputation: 102
I think you should just try and downcast it as a Bool
override func viewDidLoad() {
super.viewDidLoad()
if let currentUser = PFUser.currentUser() {
if let numberIsVerified = currentUser["phoneNumberVerified"] as? Bool {
if numberIsVerified == false {
performSegueWithIdentifier("showVerifyUserView", sender: self)
} else if numberIsVerified == true {
performSegueWithIdentifier("showMyPostsView", sender: self)
} else {
performSegueWithIdentifier("showInitialView", sender: self)
}
}
}
}
Upvotes: 1
Reputation: 6800
@Paulw11 is giving you a good hint.
You'll need to compare equatable types in Swift, so if you'e storing a Boolean as part of your current parse user you'll need to cast it as such.
You can even do it in parenthesis, in place:
(currentUser!["phoneNumberVerified"] as! Bool)
I don't recall exactly how Parse stores bools and if the types are directly compatible but that should get you on the right track. The key is the types need to be the same (or inherit from the same places in some cases) to be equitable.
Upvotes: 1