Kaynağa Gözat

refactor: use ~=(_:_:) to judge index

nuomi1 6 yıl önce
ebeveyn
işleme
15f4d17738
1 değiştirilmiş dosya ile 2 ekleme ve 6 silme
  1. 2 6
      Sources/Views/AnimatedImageView.swift

+ 2 - 6
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) {
             lock.lock()
             defer { lock.unlock() }
-            if let newValue = newValue, index >= 0 && index < array.count {
+            if let newValue = newValue, array.indices ~= index {
                 array[index] = newValue
             }
         }