What does an exclamation mark mean in the Swift language?

后端 未结 22 2668
南方客
南方客 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:26

    In this case...

    var John: Person!

    it means, that initially John will have nil value, it will be set and once set will never be nil-led again. Therefore for convenience I can use the easier syntax for accessing an optional var because this is an "Implicitly unwrapped optional"

提交回复
热议问题