How do you use the Optional variable in a ternary conditional operator?
You can not assign string value to bool but You can check it str1 is nil or not like this way : myBool = str1 != nil ? true : false print(myBool) It will print false because str1 is empty.