Skip to content
This repository has been archived by the owner on Sep 6, 2018. It is now read-only.

Workaround to fix classname issues with storyboards and customModule #36

Merged
merged 13 commits into from
Sep 7, 2017

Conversation

jlnquere
Copy link
Contributor

@jlnquere jlnquere commented Apr 15, 2017

Hey,

Here is the workaround to fix classname issues with storyboards and customModule (as described in #25) :)

Fixes #25

Copy link
Member

@djbe djbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please implement this for all storyboard templates, not just the iOS swift3 version.

@@ -1,6 +1,7 @@
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen

{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{{scene.customModule}}.{% endif %}{{scene.customClass}}{% else %}UI{{scene.baseType}}{% endif %}{% endmacro %}
{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{% if not param.ignoreTargetModule or scene.customModule != env.PRODUCT_MODULE_NAME and scene != param.module %}{{scene.customModule}}.{% endif %}{% endif %}{{scene.customClass}}{% else %}UI{{scene.baseType}}{% endif %}{% endmacro %}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, no need to add this newline.

@jlnquere
Copy link
Contributor Author

Indeed, I forgot the other templates (sorry). Just updated the PR :)

djbe
djbe previously requested changes May 2, 2017
Copy link
Member

@djbe djbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, so this branch was quite out of date. With the merge, tests are running correctly now.
I noticed an error in the if test when matching param.module, it isn't testing the correct property.

Once #2 lands, this PR needs to add the needed documentation for the ignoreTargetModule parameter.

I'm wondering if we should add tests for this. @AliSoftware thoughts?

@@ -1,6 +1,6 @@
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen

{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{{scene.customModule}}.{% endif %}{{scene.customClass}}{% else %}UI{{scene.baseType}}{% endif %}{% endmacro %}
{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{% if not param.ignoreTargetModule or scene.customModule != env.PRODUCT_MODULE_NAME and scene != param.module %}{{scene.customModule}}.{% endif %}{% endif %}{{scene.customClass}}{% else %}UI{{scene.baseType}}{% endif %}{% endmacro %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scene != param.module
should be
scene.customModule != param.module

@djbe djbe added this to the Nice To Have milestone May 8, 2017
@AliSoftware
Copy link
Collaborator

Yeah, we totally should test this, specially given how it seems to be some strange behaviour of Xcode with storyboards which might change again in future Xcode version!

@ldiqual
Copy link

ldiqual commented Jun 12, 2017

@juli1quere Bump

@jlnquere
Copy link
Contributor Author

In fact, I do not have enough knowledge of Swiftgen to write tests that check this issue :/

@djbe
Copy link
Member

djbe commented Jun 14, 2017

I'll write some tests if I can find some time this week, no promises though, might be next week.

@djbe djbe self-assigned this Aug 13, 2017
@AliSoftware
Copy link
Collaborator

Is this still relevant with the new SwiftGen 5.0 templates? If so, could we finish this PR to include it in the next release?

@djbe
Copy link
Member

djbe commented Aug 13, 2017

The current templates will always prepend the module to scene classes, even for the target module. In some scenarios, the user might want to disable this, hence this PR.

@djbe
Copy link
Member

djbe commented Aug 17, 2017

Hmmm, that's annoying... It can't compile our ignore target module files, because it can't find the custom class. The custom class is in an external module, and the import is ignored...

@AliSoftware thoughts? Add something to the filename that says "don't compile this"?

@AliSoftware
Copy link
Collaborator

Can't we create a stub-env doing the import or something?

@djbe
Copy link
Member

djbe commented Aug 17, 2017

The thing is, the best way to do this is if we could define the name of the current module when checking/compiling the code. At the time, I searched for a bit but didn't really find out how to, any help there would be useful.

If we can define a module when compiling both the output code + the definitions, I think we'll be able to solve this issue by adding the missing class to definitions.swift so that it's both in the "current" module and an imported one.

@djbe
Copy link
Member

djbe commented Aug 17, 2017

Allright, @AliSoftware no idea what you'll think of this solution, but it works 😄

@djbe djbe modified the milestones: 2.1.0, Nice To Have Aug 17, 2017
@AliSoftware
Copy link
Collaborator

I think at that point basing the decision on the file name is acceptable. But in the long run I hope we won't have more exception and cases to consider.

Otherwise we might need to make our build tests evolve e.g. use a YAML or JSON file to describe the matrix of additional options needed for each template or whatnot. But for now let's go with name matching.

@djbe djbe dismissed their stale review August 20, 2017 16:18

Implemented changes

@djbe djbe added this to the Nice To Have milestone Aug 20, 2017
@djbe djbe removed this from the 2.1.0 milestone Aug 20, 2017
@djbe djbe removed the status: WIP label Aug 27, 2017
@ldiqual
Copy link

ldiqual commented Sep 7, 2017

@djbe Is this ready to go? I see that you removed the WIP label but didn't notify the maintainers.

@djbe
Copy link
Member

djbe commented Sep 7, 2017

Eh, I left it open in case there was more feedback incoming. I suppose this can get merged 👍

@djbe djbe merged commit 1fbd5b0 into SwiftGen:master Sep 7, 2017
@ldiqual
Copy link

ldiqual commented Oct 11, 2017

@AliSoftware Sorry to bother you on this PR, but I was wondering if you had an idea of when this fix will get released?

@AliSoftware
Copy link
Collaborator

Should be included within the next version of SwiftGen next weekend

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

Successfully merging this pull request may close these issues.

Storyboards: module name for target may not match "customModule" set by Xcode
4 participants