how can i set array in EKRecurrenceRule for day of the week?

与世无争的帅哥 提交于 2019-12-02 09:48:50

You can define the days as an array of EKRecurrenceDayOfWeek like

let days = [EKRecurrenceDayOfWeek]()

Or you should cast NSMutableArray to expected argument type [EKRecurrenceDayOfWeek]

let rule = EKRecurrenceRule(recurrenceWith: .weekly, interval: 1, daysOfTheWeek: days as? [EKRecurrenceDayOfWeek], daysOfTheMonth: nil, monthsOfTheYear: nil, weeksOfTheYear: nil, daysOfTheYear: nil, setPositions: nil, end: nil)
  • work perfectly
  • Here, its simple to add specific day in Recurrencerule in dayOfTheWeek.
  • i take one mutable-array and add weekday in mutable array as per my condition.
  • In my case, i save user selected day in model class variable suppose if user select Monday and Wednesday then i save it as monday = 1 and wednesday = 1 in model class variable[e.g : routinedata.routine_monday = 1].
  • and i set that mutable-array in dayOfTheWeek. see below code.

        let tempDays = NSMutableArray()
    
        if routineData.routine_monday == 1 {
    
            tempDays.add(EKRecurrenceDayOfWeek(.monday))
            //days = [EKRecurrenceDayOfWeek(.monday)]
        }
        if routineData.routine_tuesday == 1 {
            tempDays.add(EKRecurrenceDayOfWeek(.tuesday))
        }
        if routineData.routine_wednesday == 1 {
            tempDays.add(EKRecurrenceDayOfWeek(.wednesday))
        }
        if routineData.routine_thursday == 1 {
            tempDays.add(EKRecurrenceDayOfWeek(.thursday))
        }
        if routineData.routine_friday == 1 {
            tempDays.add(EKRecurrenceDayOfWeek(.friday))
        }
        if routineData.routine_saturday == 1 {
            tempDays.add(EKRecurrenceDayOfWeek(.saturday))
        }
        if routineData.routine_sunday == 1 {
            tempDays.add(EKRecurrenceDayOfWeek(.sunday))
        }
        print("day selected\(tempDays)")
    
    
        let rule = EKRecurrenceRule(recurrenceWith: .weekly, interval: 1, daysOfTheWeek: tempDays as? [EKRecurrenceDayOfWeek], daysOfTheMonth: nil, monthsOfTheYear: nil, weeksOfTheYear: nil, daysOfTheYear: nil, setPositions: nil, end: nil)
    
        event.addRecurrenceRule(rule)
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!