How to pass a "title" on an Int-like "Uialertcontroller" with Swift?

Asked

Viewed 41 times

1

Good afternoon, you guys.

I’m calling an Alert in my code where I need its "title" to be the return id of a JSON, my json object has id and status, the id is of type Int and the status is of type String, I tried to convert the id to string, but when loading on the screen it is different from the return of json, follows below the part of my code that is loading the id and images of the simulator when executing the code:

func showActionSheetSenha(){
    var actions = [UIAlertAction]()

    for obj in containerSenha.arraySenhas{
        let status = obj.status
        let id = String(format: "%f", obj.id)

        actions.append(Alerta.createAction(id, style: .Default, handler: {(paramAction) in
            self.campoField.text = id
            self.senhaAtual = obj as Senha
        }))
    }

    Alerta.showAlert(nil, message: nil, preferredStyle: .ActionSheet, actions: actions, viewController: self) { () -> Void in
        self.view.endEditing(true)
    }
}

When I replace the id with the status to appear on Alert, it works, shows normal status. Thanks for the help.

1 answer

2


Have you tried instead of:

let id = String(format: "%f", obj.id)

do:

let id = "\(obj.id)"

???

  • 1

    It worked, I hadn’t tried it, but it worked, thank you very much :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.