且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Swift String Interpolation显示可选?

更新时间:2022-12-07 19:02:49

必须解开可选项.您必须检查它或像您一样强行拆开包装.想象一下将可选值作为放置值的方框.在访问它之前,需要将其放入.

Optionals must be unwrapped. You must check for it or force unwrap as you do. Imagine the optional as a box where you put a value. Before you can access it, you need to put it out.

if let name = nameTextField.text {
    nameLabel.text = "Hello, \(name)"
}