【发布时间】:2017-03-24 21:51:53
【问题描述】:
使用 swift3,我想处理一个错误,
public func titulo()
{do{
marca.snippet=address_components?[1].short_name
marca.title = try (address_components?[2].short_name)!+" "+(address_components?[3].short_name)!
//return titulo
}catch{
marca.title="sin titulo"
}
}
address_components 为 nil 时调用错误,但在调试中:
我能做些什么来解决这个问题?
【问题讨论】:
-
相关:How do I catch “Index out of range” in Swift?。答案很简单,你没有捕捉到运行时错误——你首先防止它发生(即by safely unwrapping the optional 并且不索引超出集合的范围)。
标签: swift