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++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -