Safe Array

김정윤·2023년 9월 7일

extension Collection {

/// Returns the element at the specified index if it is within bounds, otherwise nil.
subscript (safe index: Index) -> Element? {
    return indices.contains(index) ? self[index] : nil
}

}

profile
iOS앱개발자

0개의 댓글