Friday, April 24, 2026
HomeiOS Developmentios - You could use to create an occasion

ios – You could use [EKEvent eventWithEventStore:] to create an occasion

[ad_1]

I’ve used CalenderKit on my app. I’ve 2 sorts of customers my objective is to gather calender information from focused sort and mirror it to different focused sort.

  • First sort went fairly nicely, I’ve collected the date vary information and easily pulled it to Firebase. Works wonderful.

  • Second sort makes me lose my thoughts. So concept right here is to tug saved information from Firebase, generate it to EKEvent and mirror it to an empty Calendar through CalenderKit.

    var userEventBox: [EventBox] = []
    
    func getEvents() {
        
        self.db.assortment(XX).doc(XX).assortment("Calendar").addSnapshotListener { [self] (querySnapshot, error) in
            
            self.userEventBox = []
            
            if let e = error {
                print("There was a problem retrieving information from Firestore. (e)")
            } else {
                
                if let snapshotDocuments = querySnapshot?.paperwork {
                    
                    for doc in snapshotDocuments {
                        
                        let information = doc.information()
                        if let title = information["title"] as? String ,
                           let startDate = information["startDate"] as? String ,
                           let endDate = information["endDate"] as? String ,
                           let isAllDay = information["isAllDay"] as? Bool
                        {
                            let newEventBox = EventBox(startDate: startDate, endDate: endDate, isAllDay: isAllDay, title: title)
                            self.userEventBox.append(newEventBox)
                            print(newEventBox)
                            self.generate() //Triggers second func after information collected and saved
                        }
                    }
                }
            }
        }
    }
    

    func generate() {
        
        for era in userEventBox {

// I had points after I tried to avoid wasting information to Firebase as Date and pull it again. So I made a decision to retailer dates as String and use dateFormatter when downloaded.
            
            let isoStartDate = era.startDate
            let isoEndDate = era.endDate
            
            let dateFormatter = ISO8601DateFormatter()
            let startDate = dateFormatter.date(from:isoStartDate)!
            let endDate = dateFormatter.date(from:isoEndDate)!

      //dates formatted      

            if let occasion = EKEvent() as? EKEvent {

            occasion.title = era.title
            occasion.isAllDay = era.isAllDay
            occasion.startDate = startDate
            occasion.endDate = endDate
            occasion.calendar.cgColor = CGColor(purple: 1, inexperienced: 1, blue: 1, alpha: 1)
                self.generated = [event]
            }
            
        }
    }
    
    var generated = [EKEvent()] // This variable is the place I retailer all occasions after its generated

// And at last I'm triggering the primary getEvents func in override

    override func eventsForDate(_ date: Date) -> [EventDescriptor] {
        
        self.getEvents()
        
        let calenderKitEvents = generated.map(EKWrapper.init)
        
        return calenderKitEvents
    }
}

Drawback is I’m having this error and I couldnt figured it out for days. Any assist shall be appreciated.

[ad_2]

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments