1
0
forked from firka/firka

Use zip to iterate adjacent lessons

Replace index-based loops with zip(entry.lessons, entry.lessons.dropFirst()) in TimetableMediumView and TimetableLargeView to iterate adjacent lesson pairs. This improves readability and safety (avoids manual index arithmetic and potential out-of-bounds issues) while keeping the same break-detection logic.
This commit is contained in:
Horváth Gergely
2026-02-16 20:16:09 +01:00
committed by 4831c0
parent 61953b68d2
commit 9a99a6869a

View File

@@ -117,8 +117,8 @@ struct TimetableMediumView: View {
var hasActiveBreak: Bool {
let checkDate = entry.date
for i in 0..<entry.lessons.count - 1 {
if checkDate > entry.lessons[i].end && checkDate < entry.lessons[i + 1].start {
for (currentLesson, nextLesson) in zip(entry.lessons, entry.lessons.dropFirst()) {
if checkDate > currentLesson.end && checkDate < nextLesson.start {
return true
}
}
@@ -209,8 +209,8 @@ struct TimetableLargeView: View {
var hasActiveBreak: Bool {
let checkDate = entry.date
for i in 0..<entry.lessons.count - 1 {
if checkDate > entry.lessons[i].end && checkDate < entry.lessons[i + 1].start {
for (currentLesson, nextLesson) in zip(entry.lessons, entry.lessons.dropFirst()) {
if checkDate > currentLesson.end && checkDate < nextLesson.start {
return true
}
}