It is some time since I first needed to save event to user's calendar in iOS and realized that while iOS offers pretty good frameworks EventKit
and EventKitUI
there are not a lot of resources, tutorials or example code available online. Especially for modern versions of iOS and Swift.
I have recently written shorter post focused on parts of EvenKitUI
(links at the bottom of this post) and now I am building open source example app. 🙂
📅 The current version lists events for the next week, allows to select calendars to display events from, has option to create new events, edit existing ones and delete events with swipe gesture.
Working with calendar is far for just building custom calendar apps. You can give user super simple way to save event from your app, or maybe display today's events in their to-do list like Things 3 does.
Check out the example app on GitHub!
Thanks for reading. Here are the previous tutorials.
Top comments (8)
This is really a good app.
I am currently learning Swift and would like to create my own calendar app. Do you know how to save the selected calendars so that they are selected again when you restart the app?
Hi! I am super glad you found it useful :-) Each calendar has
calendarIdentifier
attribute which is a string and should uniquely identify it. So I would save those identifiers and use them to filter calendars when app is launched next time.If this proves to be more involved I think I could add it to the example app.
Good luck!
Thanks for the quick answer.
I will take a closer look at the calendarIdentifier. Thanks very much for the advice.
If you add it to your app, I would be very pleased. I am still in the early stages of Swift 😅.
I like it very much that you have made a tutorial for the calendar with Swift, because there are not a lot of tutorials on the internet about this topic.
I would be very happy about more tutorials on the topic of calendars with Swift 🙂.
Great! I see what I can do.
Yea there not being tutorials for calendar stuff was the main reason why I started exploring it.
Do you have something specific in mind for tutorial article? :-)
I would be interested in how to make different calendar views. I found e.g. JTAppleCalendar on the internet, which should work, but I didn't really figure out how to integrate it into your app.
But I'm not quite sure how extensive it is.
I think it would be interesting how you could program your own calendar app which you could customize to your needs.
One reason why I started with Swift is that I'm not really happy with the Calendar apps on the App Store.
I almost gave up until I found your tutorial for the EventKit. That's pretty much what I was looking for. How to program a calendar app that accesses the local calendar. My current knowledge is just not enough to develop it further, for example how to program additional views or how to save the selected calendars.
Oh I see.. Truth be told the calendar view with cells is something that is really really complicated because you need to correctly show the number of days for each month and take all that edge cases into account.
I have used JTAppleCalendar in one of the projects at my job and I think it works pretty nice. It is hard to set up though which just shows how difficult job this is.
I currently have some free time so if you want you can get in touch and I could offer you additional help and mentoring for building the calendar app.
Many thanks for the offer.
Since I don't know all the components of Swift yet, I think I've set my sights too high.
Creating a calendar app seems to be very complicated, which is probably the reason why the selection in the AppStore is not that big.
I thought that JTAppleCalendar provides the basic structure and then you only have to pass the data.
Then I will have to be satisfied with a calendar app from the AppStore.
Neat App, thanks for sharing. I have done extensive EventKit work and know how tough it is to handle all the details.
I have a question: I see you are using UIContextualAction for delete and then performing a confirmation alert. Did you attempt to mimic the standard UIKit behaviour for delete as confirmation? I am considering attempting to do so and would love to know if you tried that?