I'm working on an app that needs a Calendar section, and CalendarKit looks really great from the preview images. However, I'm new to Swift and not sure exactly how to work with it. I've installed the CocoaPod fine, but the code listed on the CalendarKit website under the Usage section here is giving me two unexpected errors when I try to add it to my project. Those errors are "'override' can only be specified on class members", and "Cannot convert return expression of type '[Event]' to return type '[EventDescriptor]'"
Here's a screenshot of the code with the errors shown, and EDIT: here's the text of the code if you don't want to go to either link
// Return an array of EventDescriptors for particular date
override func eventsForDate(_ date: Date) -> [EventDescriptor] {
let eventStore = EKEventStore()
var models = // Get events (models) from the storage / API
var events = [Event]()
for model in models {
// Create new EventView
let event = Event()
// Specify StartDate and EndDate
event.startDate = model.startDate
event.endDate = model.endDate
// Add info: event title, subtitle, location to the array of Strings
var info = [model.title, model.location]
info.append("\(datePeriod.beginning!.format(with: "HH:mm")) - \(datePeriod.end!.format(with: "HH:mm"))")
// Set "text" value of event by formatting all the information needed for display
event.text = info.reduce("", {$0 + $1 + "\n"})
events.append(event)
}
return events
}
Since this code was written exactly as specified in the Usage section, I'm at a loss of how to fix the errors - I don't want to break anything by just assuming the code is wrong and changing it as XCode suggests.
Additionally, I don't understand what exactly I'm supposed to put after "var models = " (which is followed by the note // Get events (models) from the storage / API). Do I use EKEventStore() or something like that? Could anyone link me to example code or explain what exactly is supposed to go here?
Finally, is there any documentation of how I would link the events returned by this function into a Day View or Month View / implement those views? I'd like to have both a Day View and a Month View that I switch between within the app.
Thanks so much for your time, and if there's any documentation I'm missing or example code that would explain these kinds of basic questions, I'm sorry for missing it - please link it and I'll check it out!
Please, take a look at the CalendarApp, a template repository serving as a starting point for experiments with CalendarKit. It's a sample calendar app for iOS built with CalendarKit and EventKit. It displays events stored in the EKEventStore similarly to the default calendar app.
Here is the relevant piece of code, but your implementation might be slightly different:
If something is still unclear, feel free to watch my full tutorial on getting started with CalendarKit, video link.