我想实现这一目标
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)
可能吗?
如何检查可选字符串对象在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)