I want to define a dynamic variable for my alert box. I'm getting a json from my server, like ok, error, username_in_use, etc etc.
let response = parseJSON["message"] as? String
if response == "username_in_use" {
let error_msg = "Username in already use!"
} else if response == "email_in_use" {
let error_msg = "Email address in already use!"
} else {
let error_msg = "Unknown Error!"
}
alertView.showTitle(
alertTitle: error_msg
)
But i'm getting this message:
Use of unresolved identifier 'error_msg'
How can I set a dynamic value for my alert title?
Thanks for help and sorry my poor english.
let error_msg: Stringabove the if conditions and remove theletfrom inside the conditions bracketsif ...:let error_msg = ""inif ...:error_msg = ....