Answers for "swift get all cases starting with"

0

swift get all cases starting with

// Swift 5
public enum WeekDay: Int, CaseIterable {
	case sunday = 1, monday, tuesday, wednesday, thursday, friday, saturday

    static public func allCasesStartingWith(_ startWeekday: WeekDay) -> [WeekDay] {
        guard let startIndex = WeekDay.allCases.firstIndex(of: startWeekday) else {
            return WeekDay.allCases
        }
        let firstPart = Array(WeekDay.allCases.suffix(from: startIndex))
        let lastPart = Array(WeekDay.allCases.prefix(upTo: startIndex))
    }
 }
Posted by: Guest on January-19-2022

Code answers related to "swift get all cases starting with"

Code answers related to "Swift"

Browse Popular Code Answers by Language