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

Add ability to refer file name of JSON #1098

Open
shin-carpediem opened this issue Jan 22, 2024 · 3 comments
Open

Add ability to refer file name of JSON #1098

shin-carpediem opened this issue Jan 22, 2024 · 3 comments

Comments

@shin-carpediem
Copy link

When we run SwiftGen and we get accessors for generated JSON.

We can access to the value with the key like,

// This will be a dictionary
let foo = JSONFiles.Info.key3

// This will be an [Int]
let bar = JSONFiles.Sequence.items

ref: https://github.com/SwiftGen/SwiftGen?tab=readme-ov-file#usage-example-6

However, we cannot access to the file name yet.

We might sometimes want to access to it when we use JSON stub data, or Lotte animation file, etc..

It would be helpful if you could change access level of accessors for JSON file name from internal to public.

Thank you.

@shin-carpediem shin-carpediem changed the title Add ability to refer file name of generated JSON Add ability to refer file name of JSON Jan 22, 2024
@shin-carpediem
Copy link
Author

shin-carpediem commented Jan 22, 2024

He kindly shows how to access to the file name of JSON by creating custom template.
👉 https://qiita.com/hcrane/items/2e1d28c779cda8de8454

I think it might be a bit tough, because all we just want to do is accessing the file name..

I hope this request comes up on your agenda.

@djbe
Copy link
Member

djbe commented Mar 15, 2024

Thank you for your feedback!

As you guessed, yes this can be done with a custom template. I don't think we'll change the current templates for this limited purpose.

BUT! I've been thinking about using property wrappers for exactly this purpose. That way the struct representing a file could be a static prop. wrapper, and you could access the filename via the projected value (for example). Slight problem with this is that we'd need to drop support for older Swift versions. Nothing major, as all current Xcodes (needed to publish to the App Store) have a high enough Swift version.

@shin-carpediem
Copy link
Author

shin-carpediem commented Mar 16, 2024

@djbe
Thank you for your reply.
I think your idea is nice that it will be accessing the filename with safe update!

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