如何在EKRecurrenceRule中为星期几设置数组? [英] how can i set array in EKRecurrenceRule for day of the week?

查看:283
本文介绍了如何在EKRecurrenceRule中为星期几设置数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


  • 我想在用户选择的特定日期的每周添加活动。它可以是一个或多个,也可能是全天。

  • 我存储用户在模型类变量中选择的日值。

  • 但是当我添加事件和选择天数假设今天是星期一,我选择星期二和星期三并保存。然后我检查它在星期一和星期三添加的iphone日历。

  • 我无法理解这个问题,即使我调试我的代码我在模型类变量中获得正确的日期选择值然后为什么结果不同?

  • i want to add event on every week in specific day selected by user. it can be one or more or may be all day.
  • i'm storing day value selected by user in model class variable.
  • But when i adding event and select days suppose today is monday and i select Tuesday and Wednesday and save it. then i check in iphone calendar it added in Monday and Wednesday.
  • i cant understand this problem, even i debug my code i get right value for day selection in model class variable then why result different ?

建议我任何解决方案或想法。

Suggest me any solution or idea.

谢谢

  var days = [EKRecurrenceDayOfWeek]()


        if routineData.routine_monday == 1 {
            days = [EKRecurrenceDayOfWeek(.monday)]
        }
        if routineData.routine_tuesday == 1 {
            days = [EKRecurrenceDayOfWeek(.tuesday)]
        }
        if routineData.routine_wednesday == 1 {
            days = [EKRecurrenceDayOfWeek(.wednesday)]
        }
        if routineData.routine_thursday == 1 {
            days = [EKRecurrenceDayOfWeek(.thursday)]
        }
        if routineData.routine_friday == 1 {
            days = [EKRecurrenceDayOfWeek(.friday)]
        }
        if routineData.routine_saturday == 1 {
            days = [EKRecurrenceDayOfWeek(.saturday)]
        }
        if routineData.routine_sunday == 1 {
            days = [EKRecurrenceDayOfWeek(.sunday)]
        }


        let rule = EKRecurrenceRule(recurrenceWith: .weekly, interval: 1, daysOfTheWeek: days as? [EKRecurrenceDayOfWeek], daysOfTheMonth: nil, monthsOfTheYear: nil, weeksOfTheYear: nil, daysOfTheYear: nil, setPositions: nil, end: nil)

        event.addRecurrenceRule(rule)


推荐答案


  • 完美工作

  • 这里,简单地在
    dayOfTheWeek中的Recurrencerule中添加特定日期。

  • 我采用一个mutable-array并按可变数组添加工作日我的
    条件。

  • 在我的情况下,我在模型类变量中保存用户选择的日期假设用户选择星期一和星期三然后我将其保存为模型类变量中的monday = 1和wednesday = 1 [例如: routinedata.routine_monday = 1]。

  • 我在dayOfTheWeek中设置了mutable-array。见下面的代码。

    • 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)
      


    • 这篇关于如何在EKRecurrenceRule中为星期几设置数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆