将 String 转换为 Int 类型并在控制台中打印该 Int 类型时显示错误
在展开可选值时意外发现 nil
ViewController.swift
@IBAction func btnVerifyOTP(_ sender: Any)
{
let verifyOTP =
self.storyboard?.instantiateViewController(withIdentifier: "VerifyOTP") as! VerifyOTP
self.navigationController?.pushViewController(verifyOTP, animated: true)
verifyOTP.strPhone = self.tfMobile.text!
}
ViewController2.swift
class VerifyOTP: UIViewController {
var strPhone = String()
override func viewDidLoad() {
super.viewDidLoad()
let numPhone = Int(strPhone)!
print(numPhone)
}
}
错误:此方法将打印“在展开可选值时意外发现 nil”