swift - How do you use the Optional variable in a ternary conditional operator? -
i want use optional variable ternary conditional operator throwing error error: optional cannot used boolean. doing wrong?
var str1: string? var mybool:bool mybool = str1 ? true : false
you can not assign string value bool can check str1 nil or not way :
mybool = str1 != nil ? true : false print(mybool)
it print false because str1 empty.
Comments
Post a Comment