let alertController = UIAlertController(title: "Email?", message: "Please input your email:", preferredStyle: .alert)
let confirmAction = UIAlertAction(title: "Confirm", style: .default) { (_) in
if let field = alertController.textFields?[0] {
// store your data
UserDefaults.standard.set(try.text, forKey: "userEmail")
UserDefaults.standard.synchronize()
} else {
// user did not fill field
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (_) in }
alertController.addTextField { (textField) in
textField.placeholder = "Email"
}
alertController.addAction(confirmAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
오식:
UserDefaults.standard.set(field.text, forKey: "userEmail")
보다는
UserDefaults.standard.set(try.text, forKey: "userEmail")
오류 메시지는 다음을 지적합니다.
... '(_) 유형의 값은 -> ()'를 던집니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다