What does an exclamation mark mean in the Swift language?

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

    If you use it as an optional, it unwraps the optional and sees if something is there. If you use it in an if-else statement is is code for NOT. For example,

    if (myNumber != 3){
     // if myNumber is NOT 3 do whatever is inside these brackets.
    )
    

提交回复
热议问题