我在使用nil值和if语句时遇到问题。当变量sexualPreference为零时,程序会打印出“Sexual preference is nil”和“nil”。这显然是错误的。我想知道为什么会这样?非常感谢任何帮助!
databaseRef.child("users").child(user.uid).observeSingleEventOfType(.Value, withBlock: { (snapshot) in
let mainStoryboard: UIStoryboard = UIStoryboard(name:"Main", bundle:nil)
if let sexualPreference = snapshot.value!["interestedInWomen"] {
print("Sexual Preference is not nil")
print(sexualPreference)
} else {
print("Sexual Preference is nil")
}
// ...
}) { (error) in
print(error.localizedDescription)
}