daily pastebin goal
61%
SHARE
TWEET

Untitled

a guest Dec 10th, 2018 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extension Array {
  2.     subscript(safeAt index: Int) -> Element? {
  3.         //Out of boundaries
  4.         if count <= index || index < 0 { return nil }
  5.         return self[index]
  6.     }
  7. }
  8.  
  9. let ints = [1,2,3,4]
  10. ints[safeAt: 3]
  11. ints[safeAt: -1]
  12. ints[safeAt: 0]
  13. ints[safeAt: 5]
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top