Giter Club home page Giter Club logo

Comments (9)

nemecek-filip avatar nemecek-filip commented on July 21, 2024

You mean to have headers with dates to separate the events?

from ekeventkit.example.

my4paws avatar my4paws commented on July 21, 2024

Yes... exactly that :)

from ekeventkit.example.

nemecek-filip avatar nemecek-filip commented on July 21, 2024

I see, I may try this in the future but I would like to focus mostly on EventKit itself not various options for presenting the stuff because there are so many :)

from ekeventkit.example.

my4paws avatar my4paws commented on July 21, 2024

Right, I totally understand it's beyond the scope of the demo. Thanks anyway.

from ekeventkit.example.

nemecek-filip avatar nemecek-filip commented on July 21, 2024

Or you can fork this repo and try the headers. I will be happy to help, however I am not sure how would I approach this. Probably first separate loaded events by days into some kind of [Date: [EKEVent]] dictionary and use that for List with grouping maybe

from ekeventkit.example.

my4paws avatar my4paws commented on July 21, 2024

Thanks for everything.

I've implemented your code in my project and its working the same as the demo, except I changed the interval to a single day and am passing a selected date to the "loadEvents" function from a datePicker. As below:

Code*
let startOfDay = Calendar.current.startOfDay(for: self.selectedDate.selectedDate)
let endOfDay = Calendar.current.startOfDay(for: self.selectedDate.selectedDate.advanced(by: TimeInterval.day))
**
I'm trying to return a view that shows the .selectedDate

However the list is not updating to the "selectedDate" and always shows the events for current date.
Do you have an idea how I can force the list to update to .selectedDate whenever a new date is chosen by the picker?
thanks

from ekeventkit.example.

nemecek-filip avatar nemecek-filip commented on July 21, 2024

How is your selectedDate implemented? I think it should be @State or @observableobject so SwiftUI can detect changes and rerender the views.

from ekeventkit.example.

my4paws avatar my4paws commented on July 21, 2024

In the view that contains both the datePicker & the foreach list showing the retrieved events.

Properties:

@State var selectedDate = datepicker()

body:


DatePicker(
                        selection: $selectedDate.selectedDate,
                        in: dateClosedRange,
                        displayedComponents: [.date, .hourAndMinute], label: { Text("Is hidden label") })
                    
                }
                List {
                    if eventsRepository.events?.isEmpty ?? true {
                        Text("No Walkies today")
                            .font(.headline)
                            .foregroundColor(.secondary)
                    }
                    ForEach(eventsRepository.events ?? []) { event in
                        EventRow(event: event).onTapGesture(count: 2) {
                            self.showEditFor(event)
                            self.haptics.notificationOccurred(.error)
                        }

Then I created a class that conforms to ObservableObject

class code:

class datepicker: ObservableObject{
    var selectedDate: Date = Date() // I'm thinking the problem lies here
}

EventsRepository.swift:

@ObservedObject var selectedDate = datepicker()


    func loadEvents(completion: @escaping (([EKEvent]?) -> Void)) {
        requestAccess(onGranted: {
            //let dayFromNow = Date().advanced(by: TimeInterval.day)
            let startOfDay = Calendar.current.startOfDay(for: self.selectedDate.selectedDate)
            let endOfDay = Calendar.current.startOfDay(for: self.selectedDate.selectedDate.advanced(by: TimeInterval.day))
             let predicate = self.eventStore.predicateForEvents(withStart: startOfDay, end: endOfDay, calendars: Array(self.selectedCalendars ?? []))

             let events = self.eventStore.events(matching: predicate)

             completion(events)
        }) {
            completion(nil)
        }
    }

I have really struggled with grasping the methods used to pass data from one view to another, and unfortunately have no-one at all here to ask when I get stuck or need explanations of why and how things work. Theres a LOT of trail and error involved in my coding, which is mostly error until I literally stumble upon something that works :)

from ekeventkit.example.

nemecek-filip avatar nemecek-filip commented on July 21, 2024

I would try adding @Published to the selectedDate in datepicker class and also changing @State var selectedDate = datepicker() to @ObservedObject var selectedDate = datepicker(). Also you try asking here - https://www.hackingwithswift.com/forums/swiftui I think it has better chance that someone will know how to fix it. I am SwiftUI beginner myself and it is possible that my example code is not best structured :)

from ekeventkit.example.

Related Issues (9)

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.