richardtop / CalendarKit

📅 Calendar for Apple platforms in Swift
https://www.youtube.com/watch?v=cJ63-_z1qg8
MIT License
2.48k stars 333 forks source link

Added userInfo in Descriptor. #324

Closed alensaqe closed 2 years ago

alensaqe commented 2 years ago

Could we add userInfo in the EventDescriptor?

It is in the Event but removed from EventView.

alensaqe commented 2 years ago

This a very old PR i am referring to: https://github.com/richardtop/CalendarKit/pull/29

richardtop commented 2 years ago

Hi, thanks for your pull request. I'm not sure if it's needed though, as the EventDescriptor is a requirement on a type that is imposed by CalendarKit. i.e. that's the bare minimum of information / methods required to display an event in the CK.

However, it doesn't limit you as to what the type can actually be, and you're free to add your own methods and properties. For example, instead of userInfo you could actually add your own types.

Then, in your code just cast the EventDescriptor to your type, as I do in the CalendarApp for example: https://github.com/richardtop/CalendarApp/blob/master/Calendar/CalendarViewController.swift#L130

And then you'll be able to access any other stored properties.

The whole reason for the userInfo existence is to provide a basic option to store some associated information with a provided Event class. If you'd like to have some sort of custom behavior / interface, I definitely suggest you creating your own class in the application target and conforming it to EventDescriptor.

From the CK's perspective, there is no need to have userInfo at all, since CK doesn't need it for layout / handling purposes. Let me know what you think.

Video tutorial part of how to create a custom EventDescriptor: https://youtu.be/iC4XxmExqFA?t=1714

alensaqe commented 2 years ago

Thank you for the detailed response @richardtop I will take a closer look at this and I think from what i have seen this might suffice. If that is the case i will close this PR.

We are using userInfo from an older version of the CK for storing event data like userID etc.

richardtop commented 2 years ago

We are using userInfo from an older version of the CK for storing event data like userID etc.

It's totally OK. Just make sure to cast the EventDescriptor to Event and then you'll be able to access it.

To sum up: EventDescriptor - a protocol for which any data type should conform to in order to be displayed in CalendarKit. Event Descriptor, as it's name implies, describes the event. It's the data to create an EventView.

Event is the bare minimum class conforming to the EventDescriptor, so that the user of the CalendarKit don't have to create his own class for the basic functionality. If you need something more than this, just create an own class.

That's why Event is marked as final. It's not the base class, it's just a reference implementation: https://github.com/richardtop/CalendarKit/blob/master/Sources/Timeline/Event.swift#L3

Feel free to close PR if you're able to modify your code the way I described and achieve your goal. Raise an issue if you need something else / library code modified.

richardtop commented 2 years ago

@alensaqe any news on this? Can we close it? Did you get it working?

alensaqe commented 2 years ago

I am closing this for now. I will rewrite the code as you mentioned above. Thank you @richardtop