ExtensionCollection.swift 391 B

1234567891011121314151617
  1. //
  2. // ExtensionCollection.swift
  3. // MCPlus
  4. //
  5. // Created by seo ha on 15/02/2019.
  6. // Copyright © 2019 KangSH. All rights reserved.
  7. //
  8. import Foundation
  9. extension Collection {
  10. /// Returns the element at the specified index if it is within bounds, otherwise nil.
  11. subscript (safe index: Index) -> Element? {
  12. return indices.contains(index) ? self[index] : nil
  13. }
  14. }