Check string for nil & empty

后端 未结 23 1332
感动是毒
感动是毒 2020-12-07 10:53

Is there a way to check strings for nil and \"\" in Swift? In Rails, I can use blank() to check.

I currently have this, but i

23条回答
  •  再見小時候
    2020-12-07 11:20

    I would recommend.

    if stringA.map(isEmpty) == false {
        println("blah blah")
    }
    

    map applies the function argument if the optional is .Some.
    The playground capture also shows another possibility with the new Swift 1.2 if let optional binding.

    enter image description here

提交回复
热议问题