Sauron Sauron - 6 months ago 138
iOS Question

How to setup EKRecurrenceRule rule for repeating once a week

How can I best create a

EKRecurrenceRule
in swift to allow for scheduling an event once a week, possibly several days a week.

For example, a new event is to occur every Friday and Saturday weekly.

var dayOfWeek = [EKWeekday.Friday, EKWeekday.Saturday]

EKRecurrenceRule(recurrenceWithFrequency: EKRecurrenceFrequency.Weekly, interval: 1, daysOfTheWeek: dayOfWeek)


At present, above does not work

How can this be formulated?

(The examples and tutorials for swift are sparse)

Answer

This should do it:

let friday = EKRecurrenceDayOfWeek(.Friday)
let saturday = EKRecurrenceDayOfWeek(.Saturday)

EKRecurrenceRule(recurrenceWithFrequency: .Weekly, interval: 1, daysOfTheWeek: [friday, saturday], daysOfTheMonth: nil, monthsOfTheYear: nil, weeksOfTheYear: nil, daysOfTheYear: nil, setPositions: nil, end: nil)
Comments