What does an exclamation mark mean in the Swift language?

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

    If you're familiar with C#, this is like Nullable types which are also declared using a question mark:

    Person? thisPerson;
    

    And the exclamation mark in this case is equivalent to accessing the .Value property of the nullable type like this:

    thisPerson.Value
    

提交回复
热议问题