Comments (9)
You mean to have headers with dates to separate the events?
from ekeventkit.example.
Yes... exactly that :)
from ekeventkit.example.
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.
Right, I totally understand it's beyond the scope of the demo. Thanks anyway.
from ekeventkit.example.
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.
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.
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.
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.
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)
- Any chance of a swiftUI version of this? I've found information of EventKit & EventKitui rarer than unicorn S*!t HOT 4
- Relative time giving odd results HOT 4
- Selected Calendars not being persisted HOT 1
- Recurring events issue HOT 11
- EKEventEditViewController initial focus HOT 2
- Refresh events when app is reopened/brought to foreground HOT 12
- Errors when launching the app for the first time HOT 14
- iOS 15, "bottom sheet" HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ekeventkit.example.