Xcode strips debug build from unused public Swift classes that are necessary for other targets

Originator:alex
Number:rdar://18173029 Date Originated:29-Aug-2014
Status:Closed Resolved:
Product:Developer Tools Product Version:Xcode 6.0 (6A280e)
Classification:Other Bug Reproducible:Always
 
Summary:
Let’s assume you have a Swift-project containing two targets (e.g. one for the App and one for Unit Tests). If the App-Target contains a public class that is not used in this target it cannot be instantiated in the Unit-Test-Target either because it will be stripped from the App-Build before the Unit-Test-Target has a chance to link against it.

Steps to Reproduce:
1. Open the attached sample project
2. Try to test the target on an actual device (Cmd-U)

Expected Results:
The test should compile and pass

Actual Results:
The linker fails with the error message:
Undefined symbols for architecture armv7:
  "__TMaC14BugDemoProject6ClassA", referenced from:
      __TFC19BugDemoProjectTests19BugDemoProjectTestscfMS0_FT10invocationGSQCSo12NSInvocation__S0_ in BugDemoProjectTests.o
      __TFC19BugDemoProjectTests19BugDemoProjectTestscfMS0_FT8selectorV10ObjectiveC8Selector_S0_ in BugDemoProjectTests.o
      __TFC19BugDemoProjectTests19BugDemoProjectTestscfMS0_FT_S0_ in BugDemoProjectTests.o
      _get_field_types_BugDemoProjectTests in BugDemoProjectTests.o
  "__TFC14BugDemoProject6ClassACfMS0_FT_S0_", referenced from:
      __TFC19BugDemoProjectTests19BugDemoProjectTestscfMS0_FT10invocationGSQCSo12NSInvocation__S0_ in BugDemoProjectTests.o
      __TFC19BugDemoProjectTests19BugDemoProjectTestscfMS0_FT8selectorV10ObjectiveC8Selector_S0_ in BugDemoProjectTests.o
      __TFC19BugDemoProjectTests19BugDemoProjectTestscfMS0_FT_S0_ in BugDemoProjectTests.o

Version:
Xcode Version 6.0 (6A280e) on OS X Yosemite Beta 6 compiling for iOS 8 Beta 5

Notes:


Configuration:
Everything works as expected on the iPhone Simulator
The test compiles and passes if ClassA is used at least one in the App-Target (may be achieved by toggling the line comment in ViewController.swift:13

Attachments:
https://dl.dropboxusercontent.com/u/26477957/BugDemoProject.zip

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!