What does an exclamation mark mean in the Swift language?

后端 未结 22 2192
南方客
南方客 2020-11-22 03:47

The Swift Programming Language guide has the following example:

class Person {
    let name: String
    init(name: String) { self.name = name }
    var apar         


        
22条回答
  •  青春惊慌失措
    2020-11-22 04:23

    The ! at the end of an object says the object is an optional and to unwrap if it can otherwise returns a nil. This is often used to trap errors that would otherwise crash the program.

提交回复
热议问题