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

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -