Giter Club home page Giter Club logo

ekeventkit.example's Introduction

Dynamic TypeEvent KitQuick LookApp IdeasKeyboard PreviewModern Collection Views


EKEventKit Example

You can read more about EventKit on my website.

SwiftUI version is currently work in progress. Feel free to help and suggest improvements. I have so far done just a little of SwiftUI..

Twitter: @nemecek_f License

Simple example project showing basic parts of Event Kit like loading events from calendar, selecting calendar, editing events..

📅 This project shows loading EKEvents from EKEventStore and accessing their properties to display calendar events in a Table View. It also demonstrates usage of EKCalendarChooser to let user choose calendars whose events to display. Events are added and edited via EKEventEditViewController. Events with location can be displayed on a map.

Not related stuff includes using NSTextAttachment inside NSAttributedString to display calendar colors with tinted images. And also how to implement swipe to delete in Table View with custom icon with the trailingSwipeActionsConfigurationForRowAt method.

I also have smaller projects showing EKCalendarChooser and EKEventEditViewController.

Quick overview of examples in the project

Loading calendar events

let weekFromNow = Date().advanced(by: TimeInterval.week)
        
let predicate = eventStore.predicateForEvents(withStart: Date(), end: weekFromNow, calendars: Array(selectedCalendars))

events = eventStore.events(matching: predicate)

Requesting calendar access

eventStore.requestAccess(to: .event) { (granted, error) in
    if granted {
        DispatchQueue.main.async {
            self.loadEvents()
            
            self.displaySelectedCalendars()
        }
    }
}

Selecting calendars with the EKCalendarChooser

let chooser = EKCalendarChooser(selectionStyle: .multiple, displayStyle: .allCalendars, entityType: .event, eventStore: eventStore)
chooser.delegate = self
chooser.showsDoneButton = true
chooser.showsCancelButton = true
chooser.selectedCalendars = selectedCalendars
    
let nvc = UINavigationController(rootViewController: chooser)
    
present(nvc, animated: true, completion: nil)

Implementing EKCalendarChooserDelegate

extension ViewController: EKCalendarChooserDelegate {
    func calendarChooserDidFinish(_ calendarChooser: EKCalendarChooser) {
        dismiss(animated: true, completion: nil)
        
        selectedCalendars = calendarChooser.selectedCalendars
        displaySelectedCalendars()
        loadEvents()
    }
    
    func calendarChooserDidCancel(_ calendarChooser: EKCalendarChooser) {
        dismiss(animated: true, completion: nil)
    }
}

Convenience EKEvent extensions:

extension EKEvent {
    var hasGeoLocation: Bool {
        return structuredLocation?.geoLocation != nil
    }
    
    var isBirthdayEvent: Bool {
        return birthdayContactIdentifier != nil
    }
}

Not seeing anything?

If the device or simulator has not initialized the Calendar app, the default calendar does not exist. Open the Calendar app on the device or simulated device. Build and run the app again.

Other stuff to check out

  • Example project showing Quick Look framework: Usage of QLPreviewController and QLPreviewGenerator to display and generate previews of various files like PDF, Pages documents, Keynote presentation, images and more.
  • Dynamic Type - Reference App to quickly preview Dynamic Type fonts so you can visualize them instead of just guessing.
  • App Ideas repo with some ideas for apps to build :-)
  • Keyboard Preview - small app to preview all available keyboard settings in iOS.
  • More to come

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.