-
Notifications
You must be signed in to change notification settings - Fork 0
/
CalendarTableViewController.swift
92 lines (64 loc) · 2.93 KB
/
CalendarTableViewController.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
// CalendarTableViewController.swift
// My Diabetic Manager
//
// Created by Vincenzo De Rosa on 03/02/17.
// Copyright © 2017 Vincenzo De Rosa. All rights reserved.
//
import UIKit
import EventKitUI
class CalendarTableViewController: UITableViewController {
var titles : [String] = []
var startDates : [NSDate] = []
var endDates : [NSDate] = []
var descs : [String] = []
func printEvents(){
let eventStore = EKEventStore()
let calendars = eventStore.calendars(for: .event)
for calendar in calendars {
if calendar == eventStore.defaultCalendarForNewEvents {
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 {
if event.title.hasSuffix("-MDM"){
titles.append(event.title)
startDates.append(event.startDate as NSDate)
endDates.append(event.endDate as NSDate)
descs.append(event.notes!)
}
}
}
}
}
override func viewDidLoad() {
printEvents()
super.viewDidLoad()
}
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem()
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return titles.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cellIdentifier = "events"
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! EventTableViewCell
cell.Note?.text = descs[indexPath.row]
cell.title?.text = titles[indexPath.row]
// Configure the cell...
return cell
}
}