相关疑难解决方法(0)

展开字符串并在同一if语句中检查空白

我想实现这一目标

if let large = imageLinks.large {

    if !large.isEmpty {

        result = large
    }
}
Run Code Online (Sandbox Code Playgroud)

在单个if语句中,这样的事情(这不会编译)

if let large = imageLinks.large where !large.isEmpty {

    result = large       
}
Run Code Online (Sandbox Code Playgroud)

可能吗?

swift

3
推荐指数
2
解决办法
962
查看次数

iOS Swift4如何检查string是否为nil并且不为空?

如何检查可选字符串对象在Swift4中是否既不是空字符串“”也不是nil?我最终不得不写这些奇怪的支票,因为

 //object has instance variable     
 var title: String?

 //invalid comparison - cannot compare optional and non optional
 if object.title?.count > 0
 {

 }

 //valid but ugly
 if object.titleString == nil {
      //has nil title
 }
 if let title = object.title
 {
    if title.count == 0
    {
        //has a "" string
    }
 }
Run Code Online (Sandbox Code Playgroud)

string ios swift4

3
推荐指数
1
解决办法
2738
查看次数

标签 统计

ios ×1

string ×1

swift ×1

swift4 ×1