Search Your Question

Meaning of ??, !!, !?, ?!

Ans : 

1. ?? is  Nil-Coalescing Operator. It is used to provide default value if value is nil.

let val = values["value1"] as? String ?? "default"

2. !!

i.e
struct StockFullData: Codable
{  
           var ok : Bool?  
           var sn : StockName?
}

struct StockName : Codable
{  
           let display_name : String?
}

Now Check :

print(s.sn?.display_name)      
print((s.sn?.display_name!))      
print((s.sn?.display_name!)!)      
 print((s.sn!.display_name!))

Output :

Optional("m")
Optional("m")
m
m

-> See third print, where we have used !! for extract value. I am not sure it is correct answer because it is like !)! .

3. !? : am finding answer or We can make custom operator using this .
4. ?! : am finding answer or We can make custom operator using this .

If you have any comment, question, or recommendation, feel free to post them in the comment section below!


No comments:

Post a Comment

Thanks