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) -

xcode - Swift Playground - Files are not readable -

jboss7.x - JBoss AS 7.3 vs 7.4 and differences -