数组索引安全
extension Array {
subscript(safe index: Int ) -> Element? {
return indices.contains(index) ? self[index] : nil
}
}
资源来自网络和日常整理,持续更新
extension Array {
subscript(safe index: Int ) -> Element? {
return indices.contains(index) ? self[index] : nil
}
}
资源来自网络和日常整理,持续更新
本文标题:Swift-Array Extension
本文链接:https://www.haomeiwen.com/subject/iljedftx.html
网友评论