Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Graph conform to Codable only when the vertices are Codable? #84

Open
RJPoelstra opened this issue Jan 24, 2024 · 2 comments
Open

Comments

@RJPoelstra
Copy link

Hi,

Native swift types like Array only conform to Codable when their elements are Codable.
It looks like Graph doesn't have any special need for being Codable.
Would it be possible to make Graph conform to Codable only when its vertices are? I've a use case where I'm not interested in the Graph being codable and adding conformance to the vertex type would be a lot of work.

@davecom
Copy link
Owner

davecom commented Jan 25, 2024

That's a good question. I think we already went through attempting to make Codable conditional in an earlier version of Swift but ran into some compiler limitations. I would guess this is possible now.

A couple alternatives you could do for now:

  • Make a unique ID for each vertex that you use in SwiftGraph and lookup the ancillary data for your specific needs in a separate data structure like a simple Dictionary mapping IDs to data
  • Add Codable conformance to an existing data type in an extension that just ignores the values that are not possible to make Codable

@RJPoelstra
Copy link
Author

Thanks for the suggestions. I'll look into them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants