user17928877
user17928877

Reputation: 13

transforming a weekday integer to a string - swift

I currently have an array of weekdays that represent integers which I will trigger a notification on that weekday

let weekdays:[Int] = [1,4,7]

Upvotes: 1

Views: 619

Answers (1)

grep
grep

Reputation: 593

Assuming you are ok with 1 = Sunday and 7 = Saturday, maybe something like this can be done:

First sort the array

weekdays = weekdays.sorted()

Then iterate through it

for i in weekdays {
    let weekdayString = Calendar.current.weekdaySymbols[i - 1]
    print(weekdayString)
}

Depending on your needs you may wish to use:

.weekdaySymbols
.shortWeekdaySymbols
.veryShortWeekdaySymbols

or

.standaloneWeekdaySymbols
.shortStandaloneWeekdaySymbols
.veryShortStandaloneWeekdaySymbols 

Upvotes: 0

Related Questions