Swift check string for nil & empty -


is there way check strings nil & "" in swift? in rails, can use blank() check.

i have this, seems overkill:

    if stringa? != nil {         if !stringa!.isempty {             ...blah blah         }     } 

if you're dealing optional strings, works:

(string ?? "").isempty 

the ?? nil coalescing operator returns left side if it's non-nil, otherwise returns right side.

you can use return default value:

(string ?? "").isempty ? "default" : string! 

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -