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

When using a view class from a framework, you get an undeclared type error #37

Closed ldiqual closed 9 years ago

ldiqual commented 9 years ago

Since natalie doesn't know what frameworks to import, the generated Storyboards.swift file triggers undeclared type errors for all external classes.

phimage commented 9 years ago

there is already some code to add import for external module

if viewController.showCustomImport() {
    println("import \(viewController.customModule)")

for this purpose, when you choose your view controller, you must have specified the module under the class choice

maybe due to code change, the import are now not at the good place (since 2bf28a0b1977248a0239776044accb3d7679fd6e ) I can share on monday a code that move the import at the begining of the generated file

ldiqual commented 9 years ago

@phimage I looked into my Main.storyboard and found out that there was no customModule associated with the ECSlidingViewController instance:

<viewController id="HFB-xO-gCW" customClass="ECSlidingViewController" sceneMemberID="viewController">

so there is no way for natalie to know which framework to import.

Do you have any idea why Xcode would not import from the ECSlidingViewController framework (added via Cocoapods), or how to fix the issue?

phimage commented 9 years ago

Yes, there is no module for objective-c framework, I don't know how to fix that without custom config files for natalie or command line parameter Or explain in the doc that import must be added manually for objective-c framework after each generations...

I have tested with ECSlidingViewController Trying to force module to ECSlidingViewController, I have a funny import Optional("ECSlidingViewController") The place of import in swift have no incidence so PR #41 its just to have a more clean code

krzyzanowskim commented 9 years ago

yeap. it must be defined by the user in the Interface Builder. Can't be handled in runtime. Too complicated to scan whole project/workspace looking for modules and match classess.

phimage commented 9 years ago

I think it's a real bug or a limitation to document somewhere (no objective c controller allowed or add import manually)

Maybe a MyStoryBoardName.natalie near the storyboardfile could define some code to inject or properties like "imports" to add in generated files

ldiqual commented 9 years ago

@krzyzanowskim I second @phimage 's comment. Having external framework references in a storyboard is a pretty common thing, now that many projects use cocoapods. I would suggest to at least leave the issue open so someone could look into it.

krzyzanowskim commented 9 years ago

should be mentioned somewhere in the docs.