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
Post a Comment