1

Here is my code:

import SwiftUI
import FSCalendar

class calendars: UIViewController, FSCalendarDelegate{
    var calendar = FSCalendar()

    override func viewDidLoad() {
        super.viewDidLoad()
        calendar.delegate = self
    }

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        calendar.frame = CGRect(x: 0, y: 100, width: view.frame.size.width, height: view.frame.size.width)
        view.addSubview(calendar)
    }
}

struct CalendarView: View {
    var body: some View{
            calendars()
    }
}

I don't really know is it correct to swiftui but I got an error said Return type of property 'body' requires that 'calendars' conform to 'View' I just wanna import a calendar and some kind of to do list.

KickAxe
  • 149
  • 2
  • 13

2 Answers2

3

The simplest way to include FSCalendar into SwiftUI is to wrap it in an UIView:

struct CalendarView: UIViewRepresentable {

func makeUIView(context: Context) -> UIView {
    return FSCalendar(frame: CGRect(x: 0.0, y: 40.0, width: .infinity, height: 300.0))
}

func updateUIView(_ uiView: UIView, context: Context) {
}
}

Usage in SwiftUI code:

CalendarView()
knorrbert
  • 100
  • 9
0

I got it..

struct CalendarController: UIViewControllerRepresentable {

    func makeUIViewController(context: UIViewControllerRepresentableContext<CalendarController>) -> calendars {
        return calendars()
    }

    func updateUIViewController(_ uiViewController: calendars, context: UIViewControllerRepresentableContext<CalendarController>) {
    }

}
KickAxe
  • 149
  • 2
  • 13
  • I am unable to find this approached. If possible kindly share full code snippet to used. Also drag to select date feature – jayprakash Jun 25 '20 at 11:49
  • could you share your full code to make FSCalendar work with UIViewControllerRepresentable? – Gene Aug 28 '20 at 19:24