R
R
Ruslan Shiryaev2020-10-04 16:13:26
iOS
Ruslan Shiryaev, 2020-10-04 16:13:26

How to implement an infinitely repeating cycle in FSCalendar through the subtitleFor: date function?

In my project, to implement the calendar, I use the ready-made FSCalendar module. It has a ready-made function that adds a String type signature to each date in the calendar. The task is such that in the application the user sets the number of days, and it is necessary that from a certain date this number in the form of an enumeration (1,2,3,4, etc.) be substituted as a signature for the dates. And when one cycle ended, it was followed by a new one exactly the same, and so on ad infinitum. In the existing code, I have implemented only the use of 1 loop. Code and UI below:

func calendar(_ calendar: FSCalendar, subtitleFor date: Date) -> String? {
        let cycleIsOrdered = Int(self.cyclePeriod.text!)
        if daysRange.count > 1{
            let today = daysRange[0] //First element in another dates array
            var stringDate = ""
            var countForArray = 1
            var countForSubtitle = 0
            var countArray = [String]()
            let nextDays = Calendar.current.date(byAdding: .day, value: cycleIsOrdered!-1, to: today)!
            cycleRange = datesRange(from: today, to: nextDays)
            for cycleRange in cycleRange{
                countArray.append(String(countForArray))
                countForArray += 1
                stringDate = countArray[countForSubtitle]
                if date == cycleRange{
                    return stringDate
                }
                countForSubtitle += 1
            }
        }else{
            return ""
        }
        return ""
    }


5f79ca5c7472f532548381.png

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question