Swiftgen: [Feature] General file resources from bundle

Created on 10 Nov 2019  路  9Comments  路  Source: SwiftGen/SwiftGen

I'd like to work towards adding support for parsing other file resources that need to be accessed from the bundle, usually with Bundle.main.url(forResource:withExtension:) and the like.

Looking through the issues it seems this is a desired functionality, but not much work has been towards achieving it

109, #146, #284, #496, #637

My thoughts on the implementation:

  • A good name for the subcommand might be resources
  • Correct me if I'm wrong, but it looks like inputs and filter are the best way to specify files or file types to include
  • It seems I can probably implement the generator pretty quickly duplicating functionality from the yaml and plist generators
  • Possible params:

    • enumName (default Resource)

    • publicAccess (default false)

Thoughts on template:

  • Containing enum: Resource
  • Each resource as a struct ResourceFile
  • Each resource should have a name including the extension for uniqueness and clarity
  • ResourceFile can expose two computed properties

    • url for url(forResource:withPath:)</li> <li><code>md5-0fd634b37105e2b76d4a20161746fec8</code> forpath(forResource:ofType:)

Need input on:

  • Arrays of resources
  • Handling subdirectories implicitly/explicitly/disregarding

Thoughts? Ideas? Did I miss anything?

easy enhancement

All 9 comments

Hi @mgray88!

I think you've got topics things covered.

  • For each resource(file), I'd also add a few properties such as name (without extension), extension, ... (in the context, so that in the template we can handle things appropriately)
  • Subdirectories: I think we may want to handle this like the asset catalog parser, so include directory structure information in the context, and let the template choose to use that information or not.
  • Maybe add mime type information to resource files? Not sure if it's worth it, and if there's any performance impact in trying to parse this.

Awesome. Real life got in the way since I last worked on this, but I would like to see it through. I've got a start at https://github.com/mgray88/SwiftGen/tree/feature/file-resources

If you're able, let me know what you think. I remember I was working on getting the tests set up before I went any further and ran into an issue where Swiftlint was linting my test files and complaining about the comment header. Which was just copied from the existing test files

You can always open a draft PR and we can discuss some technicalities in there

Hey @mgray88, are you still working on this? I actually had the same need and this looks like exactly what I was looking for.

@pfandrade I haven't been able to in a while. Thankfully my company is hiring an Android dev which will halve my workload. I was hoping to start back on it in a few weeks.

I'll start a PR with what I have if you'd like to help out. It's pretty far behind stable so I don't know how much of it is out of date

Hey, awesome! If I'm able to free up some time, I'll try to help out.

Is this done, or are there more pieces beyond the current files parser support?

@darknoon The feature as envisioned is complete in the PR that was merged into develop

@djbe Any news on an upcoming release?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

filip-zielinski picture filip-zielinski  路  3Comments

romk1n picture romk1n  路  7Comments

kacper1703 picture kacper1703  路  3Comments

gereons picture gereons  路  5Comments

jrmybrault picture jrmybrault  路  7Comments