10.9 C
Friday, February 9, 2024

ios – I am trying to combine CalendarKit library with SwiftUI Representable, dealing with challenge with occasions dealing with

I am making an attempt to implement CalendarKit utilizing SwiftUI’s UIViewControllerRepresentable. The instance offered by the library is in UIKit. I’ve efficiently displayed the UI, however when I attempt to go dummy occasions knowledge to show occasions in CalendarKit, the DayViewDelegate and EventDataSource strategies contained in the coordinator class will not be being referred to as, and no knowledge is being displayed.
What am I doing mistaken, or how can I obtain this? Any sort of assist can be appreciated.

My SwiftUI Representable Code:

import SwiftUI
import CalendarKit

struct DayViewControllerWrapper: UIViewControllerRepresentable {
    @Binding var selectedEvent: Occasion?
    @Binding var occasions: [EventDescriptor]
    // Callbacks for coordinator delegates
    var didSelectEventView: ((EventView) -> Void)?
    var didLongPressEventView: ((EventView) -> Void)?
    var didTapTimelineAt: ((Date) -> Void)?
    var didLongPressTimelineAt: ((Date) -> Void)?
    var didBeginDragging: (() -> Void)?
    var didTransitionCancel: (() -> Void)?
    var willMoveTo: ((Date) -> Void)?
    var didMoveTo: ((Date) -> Void)?
    var didUpdateEvent: ((EventDescriptor) -> Void)?
    func makeUIViewController(context: Context) -> DayViewController {
        let viewController = DayViewController()
        // Arrange bindings for delegates and knowledge sources
        viewController.dataSource = context.coordinator
        viewController.delegate = context.coordinator
        return viewController
    func updateUIViewController(_ uiViewController: DayViewController, context: Context) {
    func makeCoordinator() -> Coordinator {
        return Coordinator(self)
    class Coordinator: NSObject, EventDataSource, DayViewDelegate {
        var father or mother: DayViewControllerWrapper
        init(_ father or mother: DayViewControllerWrapper) {
            self.father or mother = father or mother
        // MARK: - EventDataSource
        func eventsForDate(_ date: Date) -> [EventDescriptor] {
            return father or mother.occasions
        // MARK: - DayViewDelegate
        func dayViewDidSelectEventView(_ eventView: EventView) {
            father or mother.selectedEvent = eventView.descriptor as? Occasion
            father or mother.didSelectEventView?(eventView)
        func dayViewDidLongPressEventView(_ eventView: EventView) {
            father or mother.didLongPressEventView?(eventView)
        func dayView(dayView: DayView, didTapTimelineAt date: Date) {
            father or mother.didTapTimelineAt?(date)
        func dayView(dayView: DayView, didLongPressTimelineAt date: Date) {
            father or mother.didLongPressTimelineAt?(date)
        func dayViewDidBeginDragging(dayView: DayView) {
            father or mother.didBeginDragging?()
        func dayViewDidTransitionCancel(dayView: DayView) {
            father or mother.didTransitionCancel?()
        func dayView(dayView: DayView, willMoveTo date: Date) {
            father or mother.willMoveTo?(date)
        func dayView(dayView: DayView, didMoveTo date: Date) {
            father or mother.didMoveTo?(date)
        func dayView(dayView: DayView, didUpdate occasion: EventDescriptor) {
            father or mother.didUpdateEvent?(occasion)

struct DayViewControllerWrapper_Previews: PreviewProvider {
    static var previews: some View {
        DayViewControllerWrapper(selectedEvent: .fixed(nil), occasions: .fixed([]))

My ContentView code, how i am utilizing it.

import SwiftUI
import CalendarKit

struct ContentView: View {
    @State personal var selectedEvent: Occasion?
    @State personal var occasions: [EventDescriptor] = []
    var physique: some View {
        VStack {
            Textual content("My Customized Calendar Instance")
                selectedEvent: $selectedEvent,
                occasions: $occasions,
                didSelectEventView: { eventView in
                    // Deal with occasion choice
                    print("Chosen occasion: (eventView.descriptor)")
                didLongPressEventView: { eventView in
                    // Deal with lengthy press occasion
                    print("Lengthy pressed occasion: (eventView.descriptor)")
                didTapTimelineAt: { date in
                    // Deal with faucet on timeline
                    print("Tapped timeline at: (date)")
                didLongPressTimelineAt: { date in
                    // Deal with lengthy press on timeline
                    print("Lengthy pressed timeline at: (date)")
                didBeginDragging: {
                    // Deal with start dragging
                    print("Started dragging")
                didTransitionCancel: {
                    // Deal with transition cancel
                    print("Transition canceled")
                willMoveTo: { date in
                    // Deal with will transfer thus far
                    print("Will transfer thus far: (date)")
                didMoveTo: { date in
                    // Deal with did transfer thus far
                    print("Did transfer thus far: (date)")
                didUpdateEvent: { occasion in
                    // Deal with updating occasion
                    print("Up to date occasion: (occasion)")
            .body(top: 400) // Alter body top as wanted
            .onAppear {
                // Populate occasions with dummy knowledge
    personal func generateDummyData() {
        occasions = [
            createEvent(title: "Breakfast at Tiffany's", location: "New York, 5th avenue"),
            createEvent(title: "Workout", location: "Tufteparken"),
            createEvent(title: "Meeting with Alex", location: "Home, Oslo, Tjuvholmen"),
            createEvent(title: "Beach Volleyball", location: "Ipanema Beach, Rio De Janeiro"),
            createEvent(title: "WWDC", location: "Moscone West Convention Center, 747 Howard St"),
            createEvent(title: "Google I/O", location: "Shoreline Amphitheatre, One Amphitheatre Parkway"),
            createEvent(title: "✈️️ to Svalbard ❄️️❄️️❄️️❤️️", location: "Oslo Gardermoen"),
            createEvent(title: "💻📲 Developing CalendarKit", location: "🌍 Worldwide"),
            createEvent(title: "Software Development Lecture", location: "Mikpoli MB310, Craig Federighi")
    personal func createEvent(title: String, location: String) -> EventDescriptor {
        let occasion = Occasion()
        occasion.startDate = Date()
        occasion.endDate = Date().addingTimeInterval(3600)
        occasion.textual content = "(title)n(location)"
        occasion.colour = .blue
        occasion.isAllDay = false
        occasion.userInfo = nil
        return occasion

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {

Library offered UIKit instance code:

Latest news
Related news


Please enter your comment!
Please enter your name here