Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SWIFT

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))
    }
 }
 
PREVIOUS NEXT
Tagged: #swift #cases #starting
ADD COMMENT
Topic
Name
7+9 =