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

Popular posts from this blog

c - CUDA code not processing if block properly -

oracle11g - get root domain from url Oracle sql regex_substr -

xcode - Swift Playground - Files are not readable -