如何在 EKRecurrenceRule 中为星期几设置数组?
how can i set array in EKRecurrenceRule for day of the week?
- 我想在每个星期的特定日期添加事件 select 由用户编辑。可以是一个或多个,也可以是一整天。
- 我正在存储用户在模型 class 变量中编辑的日值 select。
- 但是当我添加事件和 select 天时假设今天是星期一并且我 select 星期二和星期三并保存它。然后我查看它在周一和周三添加的 iphone 日历。
我无法理解这个问题,即使我调试了我的代码,我在模型 class 变量中得到了天 selection 的正确值那么为什么结果不同?
给我建议任何解决方案或想法。
谢谢
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)
您可以将日期定义为 EKRecurrenceDayOfWeek 数组,例如
let days = [EKRecurrenceDayOfWeek]()
或者您应该将 NSMutableArray
转换为预期的参数类型 [EKRecurrenceDayOfWeek]
let rule = EKRecurrenceRule(recurrenceWith: .weekly, interval: 1, daysOfTheWeek: days as? [EKRecurrenceDayOfWeek], daysOfTheMonth: nil, monthsOfTheYear: nil, weeksOfTheYear: nil, daysOfTheYear: nil, setPositions: nil, end: nil)
- 工作完美
- 在这里,在Recurrencerule中添加特定的一天很简单
dayOfTheWeek.
- 我采用一个可变数组并根据我的方法在可变数组中添加工作日
健康)状况。
- 在我的例子中,我将用户 selected 天保存在模型 class 变量中假设如果用户 select 星期一和星期三,那么我将其保存为星期一 = 1 和星期三 = 1在模型 class 变量中[例如:routinedata.routine_monday = 1].
我在 dayOfTheWeek 中设置了可变数组。见下面的代码。
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)
- 我想在每个星期的特定日期添加事件 select 由用户编辑。可以是一个或多个,也可以是一整天。
- 我正在存储用户在模型 class 变量中编辑的日值 select。
- 但是当我添加事件和 select 天时假设今天是星期一并且我 select 星期二和星期三并保存它。然后我查看它在周一和周三添加的 iphone 日历。
我无法理解这个问题,即使我调试了我的代码,我在模型 class 变量中得到了天 selection 的正确值那么为什么结果不同?
给我建议任何解决方案或想法。
谢谢
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)
您可以将日期定义为 EKRecurrenceDayOfWeek 数组,例如
let days = [EKRecurrenceDayOfWeek]()
或者您应该将 NSMutableArray
转换为预期的参数类型 [EKRecurrenceDayOfWeek]
let rule = EKRecurrenceRule(recurrenceWith: .weekly, interval: 1, daysOfTheWeek: days as? [EKRecurrenceDayOfWeek], daysOfTheMonth: nil, monthsOfTheYear: nil, weeksOfTheYear: nil, daysOfTheYear: nil, setPositions: nil, end: nil)
- 工作完美
- 在这里,在Recurrencerule中添加特定的一天很简单 dayOfTheWeek.
- 我采用一个可变数组并根据我的方法在可变数组中添加工作日 健康)状况。
- 在我的例子中,我将用户 selected 天保存在模型 class 变量中假设如果用户 select 星期一和星期三,那么我将其保存为星期一 = 1 和星期三 = 1在模型 class 变量中[例如:routinedata.routine_monday = 1].
我在 dayOfTheWeek 中设置了可变数组。见下面的代码。
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)