Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Storyboard.swift and symbol(s) not found for architecture, only in Release #57

Closed
alessandroorru opened this issue Nov 10, 2015 · 10 comments

Comments

@alessandroorru
Copy link

I'm currently having an issue with generated Storyboard.swift code, but only in release mode. I'm using Xcode 7.1, targeting iOS 9 just for iOS.

The affected code is the call to initialViewController(), while using other methods works fine.
For example in my case:
let navigationController = UIStoryboard.Scene.Main.initialViewController() as! UINavigationController.

Building for archive spits out this error:

Undefined symbols for architecture armv7:
  "direct type metadata for ext.MyApp.__ObjC.UIStoryboard.Scene.Main", referenced from:
      function signature specialization <Arg[0] = Dead and Owned To Guaranteed, Arg[1] = Dead and Owned To Guaranteed> of MyApp.AppDelegate.application (MyApp.AppDelegate)(__ObjC.UIApplication, didFinishLaunchingWithOptions : [__ObjC.NSObject : Swift.AnyObject]?) -> Swift.Bool in AppDelegate.o
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I don't know if this is just a compiler bug due to a specific optimization flag or if it is related to swiftgen. Anyone else is having the same issue?

@AliSoftware
Copy link
Collaborator

Maybe related to #56 (I mean, that might be a compiler bug due to Whole Module Optimization turned on)?
The compiler error message seems to be very similar at least, even if that's not on the same part of the code (colors vs. storyboards)

@AliSoftware
Copy link
Collaborator

Note that in the meantime, until Apple fixes that bug, you can disable WMO in your Release build to workaround this linker bug.

@AliSoftware AliSoftware changed the title Storyboard.swift and symbol(s) not found for architecture Storyboard.swift and symbol(s) not found for architecture when WMO is enabled Nov 11, 2015
@alessandroorru
Copy link
Author

Unfortunately I didn't have WMO enabled 😕

@AliSoftware
Copy link
Collaborator

@alessandroorru I can't reproduce the issue on a simple project here.

Could you create a sample project to demonstrate the issue and help us reproduce?

@AliSoftware AliSoftware changed the title Storyboard.swift and symbol(s) not found for architecture when WMO is enabled Storyboard.swift and symbol(s) not found for architecture, only in Release Nov 22, 2015
@alessandroorru
Copy link
Author

@AliSoftware sure!

Here is a sample project. The scheme setting is already set at "Release" also for running in simulator, so if you just press play you should see it fail. If you change it back to "Debug" it will work as expected.

BTW, I'm using Xcode 7.1.1 (7B1005), so the last stable version.

Let me know if it fails also for you.. hope it helps ;)

https://www.dropbox.com/s/v4rm0w11q2x2go9/TestFailingSwiftgen.zip?dl=1

@jmacmullin
Copy link

I hit this bug too. I also did not have the whole module optimiser enabled, but just set to the default for release builds (Fast [-O]). When I disabled the optimiser, I no longer encountered the error.

@AliSoftware
Copy link
Collaborator

Ah thx for the feedback @jmacmullin that's definitely worth filing a dedicated radar to Apple!

@AliSoftware
Copy link
Collaborator

Ok so I can confirm that:

  • I also have the bug with @alessandroorru 's sample project when building in Release too (and not in Debug)
  • This is a known LLVM issue (an engineer at Apple working on the Swift compiler confirmed it) when declaring nested types in extensions and building with optimizations turned on
  • There are two workaround possible:
    • Don't use -O (change this in your Build Settings of the Release configuration of your project)
    • Or don't use nested types in class extensions — which is what the default template of SwiftGen does — until Apple fixes that bug (†).

(†) For the second workaround, the fix consists of generating top-level struct UIStoryboardScene and struct UIStoryboardSegue instead of declaring struct Scene and struct Segue as a nested type in extension UIStoryboard. The result being that you'll have to do UIStoryboardScene.Main.initialViewController() instead of UIStoryboard.Scene.Main.initialViewController(). Should be quite easy to make a PR changing the templates bundled in SwiftGen to apply this workaround ;)

@ryanbooker
Copy link
Contributor

What names should the top level structs have? Calling them UIXXX seems risky and UIStoryboardSegue already exists, obviously. I was thinking to drop the UI prefix.

I need this too, so I'll just fix it if no one else has. :)

@AliSoftware
Copy link
Collaborator

@ryanbooker One can always choose different enum names using the --sceneEnumName and --segueEnumName options, but as you point out we can't use UIStoryboardSegue for the default names indeed. I'd vote for StoryboardSegue and StoryboardScene

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

No branches or pull requests

4 participants