Closed R35Master closed 1 year ago
I have edited the code and this is how it looks like `
func getEvents() {
self.db.collection(XX).document(XX).collection("Calendar").addSnapshotListener { [self] (querySnapshot, error) in
self.userEventBox = []
if let e = error {
print("There was an issue retrieving data from Firestore. \(e)")
} else {
if let snapshotDocuments = querySnapshot?.documents {
for doc in snapshotDocuments {
let data = doc.data()
if let title = data["title"] as? String ,
let startDate = data["startDate"] as? String ,
let endDate = data["endDate"] as? String ,
let isAllDay = data["isAllDay"] as? Bool
{
let newEventBox = EventBox(startDate: startDate, endDate: endDate, isAllDay: isAllDay, title: title)
self.userEventBox.append(newEventBox)
print(newEventBox)
self.generate()
}
}
}
}
}
}
func generate() {
for generation in userEventBox {
let isoStartDate = generation.startDate
let isoEndDate = generation.endDate
let dateFormatter = ISO8601DateFormatter()
let startDate = dateFormatter.date(from:isoStartDate)!
let endDate = dateFormatter.date(from:isoEndDate)!
if let event = EKEvent() as? EKEvent {
event.title = generation.title
event.isAllDay = generation.isAllDay
event.startDate = startDate
event.endDate = endDate
event.calendar.cgColor = CGColor(red: 1, green: 1, blue: 1, alpha: 1)
self.generated = [event]
}
}
}
var generated = [EKEvent()]
override func eventsForDate(_ date: Date) -> [EventDescriptor] {
self.getEvents()
let calenderKitEvents = generated.map(EKWrapper.init)
return calenderKitEvents
}
} `
Now I have this error Thread 1: "You must use [EKEvent eventWithEventStore:] to create an event"
I will really lose my mind. Please help @richardtop
Please post on stackoverflow first.
Let's continue there.
New Issue Checklist
Issue Description
Hi @richardtop I dont like to create tons of topics but my brain is melting and I cant figure it out. So the reason I am using CalenderKit is basically getting a user calendar data and show it to other related user.
First side everything works great, no dubt. I am capturing 35 days of calendar data and pulling it to firebase with +startdate +endDate +isallDay + color + title with for - in loop.
Second side with same path I am taking that captured user's data with for in loop, append it and keeping it and what happens is when I try to do .map(EKWrapper.init) that variable I am having this issue
public var color: UIColor { get { UIColor(cgColor: ekEvent.calendar.cgColor) ==>> error : Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value <<== .calender is red and underlined. Please find the code I use below: } }
Code I'm using with CalendarKit
Result I am trying to achieve
StackOverflow Question link