サンプル:alert表示のInputboxで現在のViewControllerのname属性を修正するロジック
let ac = UIAlertController(title: "New Name", message: "", preferredStyle: .alert) let done = UIAlertAction(title: "Done", style: .default) { [weak self, weak ac](action) in guard let textFields = ac?.textFields else { return } for textField in textFields { if textField.tag == 1 { guard let newName = textField.text else { return } self?.name = newName } } } let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil) ac.addTextField(configurationHandler: {(textField:UITextField!) -> Void in textField.text = self.name textField.tag = 1 }) ac.addAction(done) ac.addAction(cancel) present(ac, animated: true, completion: nil)