Matt
Matt

Reputation: 365

Swift 3 string comparison not working in if conditional statement

I've this small piece of code. If the value is 0 then I want to go into if. This code never goes into if even if prints value 0. Can anyone point me what I'm doing wrong?

let value = (data?.object(forKey: "amount") as? String)!
print(String(describing: type(of: value)), value)
if value == "0" {
    print("if")
}else{
    print("else")
}

Print: String 0 else

Upvotes: 0

Views: 225

Answers (1)

Matt
Matt

Reputation: 365

Somehow I figured out that the string was actually "0 " which was not obvious from print().

Upvotes: 1

Related Questions