Некорректно отправляются данные

swift

#1

Добрый день, есть функция , которая отправляет запрос в добавление друзья. В функции есть UIAlertController с текстовыми полем. Проблема состоит в том , что текст не отправляется . Прошу помощи в решении проблемы. Спасибо

 @IBAction func btnInviteFriends(_ sender: Any) {
    
    
    let alert = UIAlertController(title: "Send request",
                                  message: "to invite to friends",
                                  preferredStyle: .alert)
    let submitAction = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
       let textField = alert.textFields![0]
        
        // Get 1st TextField's text
        RequestClient()
            .setURL(self.api.friendsRequest)
            .addParam("id", value: self.userId)
            .addParam("message", value: self.message)
            .setMethod(.post)
            .request(completionHandler: { json in
                print(json)
                
            })
        
    })
    
    let cancel = UIAlertAction(title: "Cancel", style: .destructive, handler: { (action) -> Void in })
    alert.addTextField { (textField: UITextField) in
        textField.keyboardAppearance = .dark
        textField.keyboardType = .default
        textField.autocorrectionType = .default
        textField.placeholder = "Your message"
        textField.clearButtonMode = .whileEditing
    }
    alert.addAction(submitAction)
    alert.addAction(cancel)
    present(alert, animated: true, completion: nil)
}

#2

А где добавленный текст из текстового поля?


#3

Я его добавляю через:

alert.addTextField { (textField: UITextField) in
    textField.keyboardAppearance = .dark
    textField.keyboardType = .default
    textField.autocorrectionType = .default
    textField.placeholder = "Your message"
    textField.clearButtonMode = .whileEditing

А вот как его отправить , до конца не понимаю. В .addParam конечно же не могу его включить;


#4
let submitAction = UIAlertAction(title: "OK", style: .default, handler: { (action) -> Void in
       let textField = alert.textFields![0]
        
        // Get 1st TextField's text
        RequestClient()
            .setURL(self.api.friendsRequest)
            .addParam("id", value: self.userId)
            .addParam("message", value: self.message)
            .setMethod(.post)
            .request(completionHandler: { json in
                print(json)
                
            })
        
    })

Вы тут вытащили поле, но не передаете его значение.