从日历中检索带有标识符的事件时应用程序崩溃
App crash while retrieve event with Identifier from calendar
当用户从日历中手动删除事件并且应用程序尝试从 EKEventStore 中检索带有标识符的 EKEvent 时,应用程序会崩溃并出现以下错误。
Error getting event with identifier AB78AC19-BD17-4290-8A21-4BF948089C12:66F6F5BC-BF61-401A-B808-44A555F7E63E:
Error Domain=EKCADErrorDomain Code=1010 "The operation couldn’t be
completed. (EKCADErrorDomain error 1010.)" fatal error: unexpectedly
found nil while unwrapping an Optional value
这是用于获取标识符为
的事件的代码
let eventStore = EKEventStore()
let event = eventStore.event(withIdentifier: identifier as String)!
请帮我解决这个问题。
检查事件是否存在:
let eventStore = EKEventStore()
if let event = eventStore.event(withIdentifier: identifier as String) {
//do what you need with the event
}
当用户从日历中手动删除事件并且应用程序尝试从 EKEventStore 中检索带有标识符的 EKEvent 时,应用程序会崩溃并出现以下错误。
Error getting event with identifier AB78AC19-BD17-4290-8A21-4BF948089C12:66F6F5BC-BF61-401A-B808-44A555F7E63E: Error Domain=EKCADErrorDomain Code=1010 "The operation couldn’t be completed. (EKCADErrorDomain error 1010.)" fatal error: unexpectedly found nil while unwrapping an Optional value
这是用于获取标识符为
的事件的代码let eventStore = EKEventStore()
let event = eventStore.event(withIdentifier: identifier as String)!
请帮我解决这个问题。
检查事件是否存在:
let eventStore = EKEventStore()
if let event = eventStore.event(withIdentifier: identifier as String) {
//do what you need with the event
}