I'm still confused about the ? in swift . I even googled what it means but I still don't understand it. Can someone please help me?
4/11/2020 8:54:34 PM
unknowncoder245 Answers
New AnswerThe question mark(?) can be used as a ternary operator. The kind of expression it does works much like if-else statement. In other circumstances, the question mark can be used to declare the type of a variable as optional type. This variable may or may not have a value. Perhaps if you provide a piece of short code you struggle to understand, I could help you better. Here is more about optional type and how to unwrap it with exclamation mark(!). https://medium.com/@agoiabeladeyemi/optionals-in-swift-2b141f12f870
//You can also use it (?) like this exemple : let x = 10 // while x < 20 , i take value of i else i take value of 2*x var i = x<20 ? x : 2*x
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message