krzyzanowskim / Natalie

Natalie - Storyboard Code Generator (for Swift)
http://blog.krzyzanowskim.com/2015/04/15/natalie-storyboard-code-generator/
MIT License
1.17k stars 74 forks source link

Special processing for customModuleProvider="target" for view controllers? #125

Closed alkalim closed 6 years ago

alkalim commented 6 years ago

When you start fresh storyboard with one target the view controller definition in the storyboard looks like this:

<viewController id="BYZ-38-t0r" customClass="ViewController" customModuleProvider="target" sceneMemberID="viewController">

Given that Inherit module from target option is on and you don't assign module explicitly. However when you define more targets and assign this storyboard to them at some point Xcode adds customModule attribute but leaves customModuleProvider="target" as is:

<viewController id="BYZ-38-t0r" customClass="ViewController" customModule="mytarget1" customModuleProvider="target" sceneMemberID="viewController">

Apparently it goes unnoticed because customModuleProvider has a higher precedence over customModule and is just not used during class load if customModuleProvider="target" is specified.

However Natalie processes customModule attribute regardless of customModuleProvider which results in fully qualified class names. For example, if I have targets mytarget1 and mytarget2 and the storyboard "remembers" customModule="mytarget1" Natalie will generate the following code:

static func instantiateInitialViewController() -> mytarget1.ViewController {
        return self.storyboard.instantiateInitialViewController() as! mytarget1.ViewController
}

Which will not build for mytarget2.

I would propose to add a special case in ViewController.swift, property customClassWithModule : Change: if let moduleName = self.customModule { To: if let moduleName = self.customModule, customModuleProvider != "target" {

phimage commented 6 years ago

Hi, could you PR? Maybe edit one of the example to be able to test it

alkalim commented 6 years ago

could you PR?

Done!

Maybe edit one of the example to be able to test it

I have tested it with the following steps:

screen shot 2018-06-20 at 01 13 14 screen shot 2018-06-20 at 01 25 21