Skip to content

Instantly share code, notes, and snippets.



Last active May 17, 2018
What would you like to do?
swift array extension
extension Array {
subscript (safe index: Int) -> T? {
get {
return indices(self) ~= index ? self[index] : nil
set (value) {
if value == nil {
if !(indices(self) ~= index) {
NSLog("WARN: index:\(index) is out of range, so ignored. (array:\(self))")
self[index] = value!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.