gpt4 book ai didi

ios - 如何在 EKRecurrenceRule 中为星期几设置数组?

转载 作者:行者123 更新时间:2023-11-28 15:37:54 25 4
gpt4 key购买 nike

  • 我想在用户选择的特定日期的每周添加事件。可以是一个或多个,也可以是一整天。
  • 我将用户选择的日值存储在模型类变量中。
  • 但是当我添加事件并选择日期时假设今天是星期一,我选择星期二和星期三并保存。然后我查看它在周一和周三添加的 iphone 日历。
  • 我无法理解这个问题,即使我调试了我的代码,我也能在模型类变量中获得正确的日期选择值,那么为什么结果不同?

  • 向我提出任何解决方案或想法。

谢谢

  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)

关于ios - 如何在 EKRecurrenceRule 中为星期几设置数组?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44111168/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com