Swift Get All Cases Starting With

[Solved] Swift Get All Cases Starting With | Swift - Code Explorer | yomemimo.com
Question : swift get all cases starting with

Answered by : rens-wijnmalen

// 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)) } }

Source : | Last Update : Wed, 26 Jan 22

Answers related to swift get all cases starting with

Code Explorer Popular Question For Swift