Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从包含特定标题的日历中获取事件?_Ios_Swift_Events_Calendar - Fatal编程技术网

Ios 如何从包含特定标题的日历中获取事件?

Ios 如何从包含特定标题的日历中获取事件?,ios,swift,events,calendar,Ios,Swift,Events,Calendar,我是斯威夫特的新手! 我只是想知道如何从日历中获取包含以下名称的所有事件: 我今天的心情很开心,我今天的心情很开心,我今天的心情很悲伤,我今天的心情很温和,我今天的心情很悲伤。 提前谢谢 这是我目前掌握的代码: import EventKit var titles : [String] = [] var startDates : [NSDate] = [] var endDates : [NSDate] = [] let eventStore = EKEventStore() let cal

我是斯威夫特的新手! 我只是想知道如何从日历中获取包含以下名称的所有事件:

我今天的心情很开心,我今天的心情很开心,我今天的心情很悲伤,我今天的心情很温和,我今天的心情很悲伤。 提前谢谢

这是我目前掌握的代码:

import EventKit

var titles : [String] = []
var startDates : [NSDate] = []
var endDates : [NSDate] = []

let eventStore = EKEventStore()
let calendars = eventStore.calendars(for: .event)

 for calendar in calendars {
            if calendar.title == "My mood today was very happy" || calendar.title == "My mood today was happy" || calendar.title == "My mood today was very sad" || calendar.title == "My mood today was moderate" || calendar.title == "My mood today was sad"{

                let oneMonthAgo = NSDate(timeIntervalSinceNow: -30*24*3600)
                let oneMonthAfter = NSDate(timeIntervalSinceNow: +30*24*3600)

                let predicate = eventStore.predicateForEvents(withStart: oneMonthAgo as Date, end: oneMonthAfter as Date, calendars: [calendar])

                let events = eventStore.events(matching: predicate)

                for event in events {
                    titles.append(event.title)
                    startDates.append(event.startDate! as NSDate)
                    endDates.append(event.endDate! as NSDate)
                    
                }
            }
        }
        print("Title is \(titles)")
        print("Start dates are \(startDates)")
        print("End dates are \(endDates)")
            
     

你在这段代码中遇到了什么问题?数组是空的你有这些名称的事件吗?你知道如何调试和检查发生了什么吗?我有日历中的事件名称你在这段代码中遇到了什么问题?数组是空的你有这些名称的事件吗?你知道如何调试和检查发生了什么吗?我有日历中的事件名称