Browse Source

Merge pull request #1259 from nuomi1/refactor/SafeArray-subscript

refactor: SafeArray subscript
Wei Wang 6 years ago
parent
commit
1606beb680
1 changed files with 3 additions and 7 deletions
  1. 3 7
      Sources/Views/AnimatedImageView.swift

+ 3 - 7
Sources/Views/AnimatedImageView.swift

@@ -571,17 +571,13 @@ class SafeArray<Element> {
         get {
             lock.lock()
             defer { lock.unlock() }
-            if index >= 0 && index < array.count {
-                return array[index]
-            } else {
-                return nil
-            }
+            return array.indices ~= index ? array[index] : nil
         }
         
-        set(newValue) {
+        set {
             lock.lock()
             defer { lock.unlock() }
-            if let newValue = newValue, index >= 0 && index < array.count {
+            if let newValue = newValue, array.indices ~= index {
                 array[index] = newValue
             }
         }