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

Storyboards: module name for target may not match "customModule" set by Xcode #25

Closed
djbe opened this issue Feb 20, 2017 · 13 comments · Fixed by #36
Closed

Storyboards: module name for target may not match "customModule" set by Xcode #25

djbe opened this issue Feb 20, 2017 · 13 comments · Fixed by #36

Comments

@djbe
Copy link
Member

djbe commented Feb 20, 2017

If a project has 2 targets A and B, and a storyboard file is in both, whenever a scene's custom class is set in Xcode's UI, the customModule will also be (automatically) set to the current target's name in the storyboard's XML.

SwiftGen (by default) will preprend the module's name if there is one in the storyboard's XML, so this realisation above means that it will prepend the module name to any custom class, which does not allow generated files to be included by both targets A and B.

@AliSoftware
Copy link
Collaborator

@juli1quere care to add some more information about this issue you encountered, or even a sample project to reproduce? Thanks.

@jlnquere
Copy link
Contributor

OK, this issue is a little bit strange. I wanted to build a demo project ... But everything is working as expected (i.e. SwiftGen do not add the module name).

So, I dug into my original project. When I check with interface builder, my scenes are not set up with a custom module. But when I open it as an XML file, customModule is set ...

screen shot 2017-02-20 at 14 01 20

<viewController id="8d1-8q-ASZ" customClass="MainViewController" customModule="Kwote" customModuleProvider="target" sceneMemberID="viewController">

After removing all these customModule="Kwote" manualy, everything works as expected. To sum up: this is clearly an Interface Builder issue, SwiftGen works as expected.

@AliSoftware
Copy link
Collaborator

Should we close this then? Or is it worth making a note somewhere to document this Interface Builder issue?

@jlnquere
Copy link
Contributor

jlnquere commented Feb 20, 2017

So @djbe: the solution for you would be to check that your scenes are not bound to a specific module. And you'll have to check in Interface Builder AND with XML editor :/

Edit: @AliSoftware just told me that you're not facing this issue ... Anyway :)

@djbe
Copy link
Member Author

djbe commented Feb 20, 2017

@juli1quere I think this is the behaviour Interface Builder is meant to have. Even if it's not, that doesn't mean we can can't do anything about it.

We could modify the following line:
{% macro className scene %}{% if scene.customClass %}{% if scene.customModule %}{{scene.customModule}}.{% endif %}{{scene.customClass}}{% else %}UI{{scene.baseType}}{% endif %}{% endmacro %}
To add a test around the customModule bit:
{% 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 %}

Essentialy, you could add a cli parameter --param ignoreTargetModule, to disable prefixing custom classes with the target module. And if you're compiling this with multiple targets, add --param module=Kwote to always match the module in the storyboard.

@djbe
Copy link
Member Author

djbe commented Feb 20, 2017

By the way, you could test this right now using a custom template. With SwiftGen 4.2, you can pass along any custom parameters to the template.

@jlnquere
Copy link
Contributor

jlnquere commented Feb 23, 2017

Indeed, that could be a good option !

In fact, I think this IB issue is not transitory. I manually fixed my storyboard. Few days after, I updated it (just changed the content mode of an UIImageView). And, when I look my changelog, IB put back customModule="Kwote" on every scene. Damned ! For example:

-                <viewController id="8d1-8q-ASZ" customClass="MainViewController"  customModuleProvider="target" sceneMemberID="viewController">
+                <viewController id="8d1-8q-ASZ" customClass="MainViewController" customModule="Kwote" customModuleProvider="target" sceneMemberID="viewController">

I'll try the solution you suggest quickly.

@jlnquere
Copy link
Contributor

jlnquere commented Feb 23, 2017

So @djbe: I tried your workaround, it works perfectly. Thank you !

Now, I will try to understand why IB continue to add the customModule field.

@djbe
Copy link
Member Author

djbe commented Feb 23, 2017

I honestly think they just made it the default behaviour to avoid some class name ambiguity?
I'm glad the trick worked, we'll have to add it to the documentation when we get to it.

Ref #2.

@djbe djbe closed this as completed Feb 23, 2017
@jlnquere
Copy link
Contributor

Do you want me to make a PR with your workaround ?

@djbe
Copy link
Member Author

djbe commented Feb 23, 2017

Err sorry, getting some issues/PRs confused. Yes, a PR would be welcome!

@djbe djbe reopened this Feb 23, 2017
@ldiqual
Copy link

ldiqual commented Apr 7, 2017

@juli1quere Any update on this?

@jlnquere
Copy link
Contributor

Hey ! I'm sorry, I did not seen the notifications on this.

PR incoming 👨‍🚀

jlnquere added a commit to jlnquere/templates that referenced this issue Apr 15, 2017
jlnquere added a commit to jlnquere/templates that referenced this issue Apr 17, 2017
@djbe djbe added this to the Nice To Have milestone May 8, 2017
@djbe djbe closed this as completed in #36 Sep 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants