Is there a way to add an event to calendar with SwiftUI?

Viewed 3520

I've seen that in Swift was so easy and fast to use... Right now can't find anything similar in swiftUI, i tried searching for EventKit but with 0 results.

2 Answers

What you're trying to accomplish is a data operation done using the Swift language. SwiftUI is a framework for creating user interfaces. Generally, you want to separate your business logic (backend code like storing and editing data) with your UI logic (which is a visual representation of your data).

For your question, you would want to create a separate class that can add/remove data from Calendar. While it's a bit too much code to discuss in a StackOverflow post, you can refer to a couple of documents to get started:

Apple's EventKit Documentation

This link shared by bartonstanley is also useful:

Add Event to Calendar iOS Tutorial

Once you have created a class that can manage calendar information, you should either instantiate it and create it in the view you need, or use the Singleton model. This way, you don't have a SwiftUI view with 100+ lines of EventKit-related code that doesn't involve the UI.

I hope this helps!

Related