1

I am using the following code to compare two strings and show a different image depending on the comparison:

let sameQuotation = "0"
        if prioridad == sameQuotation {
            print("es 0-")
            let image11 = UIImage(named: "pri0") as UIImage?
        }


        let sameQuotation1 = "1"
        if prioridad == sameQuotation1 {
            print("es 1-")
            let image11 = UIImage(named: "pri1") as UIImage?
        }

The "print" action is done perfectly, but the image doesn't change.

I am new to Swift and may be there is something wrong with my code.

Thank you.

1 Answer 1

5

It's not changing because you're redeclaring image11 within each conditional. Change let image11 = ... to image11 = ... to access what I assume is a previously declared version of image11, ex:

if prioridad == sameQuotation {
    print("es 0-")
    image11 = UIImage(named: "pri0") as UIImage?
}


let sameQuotation1 = "1"
if prioridad == sameQuotation1 {
    print("es 1-")
    image11 = UIImage(named: "pri1") as UIImage?
}
Sign up to request clarification or add additional context in comments.

1 Comment

You should accept Lyndsey's answer if it solves your problem. (And up-vote it if you haven't already.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.