From 603724005262d219c7bb26cf141f1c9cd08b79c7 Mon Sep 17 00:00:00 2001 From: Gerrit Linnemann Date: Sun, 16 Aug 2020 10:28:42 +0200 Subject: [PATCH] IndexOutOfBounds abgefangen --- YAPS/YAPS/ContentView.swift | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/YAPS/YAPS/ContentView.swift b/YAPS/YAPS/ContentView.swift index a2b18cc..bfef6ff 100644 --- a/YAPS/YAPS/ContentView.swift +++ b/YAPS/YAPS/ContentView.swift @@ -45,9 +45,14 @@ struct ContentView: View { switch direction { case MoveCommandDirection.down: - newIndex += 1 + let max = self.fileList.count + if (newIndex + 1) < max { + newIndex += 1 + } case MoveCommandDirection.up: - newIndex -= 1 + if (newIndex - 1) >= 0 { + newIndex -= 1 + } default: newIndex += 0 }