What does an exclamation mark mean in the Swift language?

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

    Simple the Optional variable allows nil to be stored.
    
    var str : String? = nil
    
    str = "Data"
    
    To convert Optional to the Specific DataType, We unwrap the variable using the keyword "!"
    
    func get(message : String){
       return
    }
    
    get(message : str!)  // Unwapped to pass as String
    

提交回复
热议问题