I have an Xcode 7-beta5 workspace setup like so:
- Application target written in Objective-C.
- UI Test target written in Swift 2.0.
The Application Target has a header file with `extern NSString * const` variables defined:
// SomeClass.h
extern NSString * const myConstantString;
// SomeClass.m
NSString * const myConstantString = @"Hello there!";There is a bridging header setup so the UI Test target in Swift 2.0 does see SomeClass.h:
// MyApplication-Bridging-Header.h
#import "SomeClass.h"When you write the constant in a Swift test, the editor does highlight `myConstantString` indicating that it can see it:
func someTest() {
let app = XCUIApplication()
XCTAssert(app.staticTexts["someStatusLabel"].label == myConstantString)
}However when I attempt to compile and run the UI Test target on the iOS Simulator (iPhone 6 (9.0)), I get the following error:
Undefined symbols for architecture x86_64:
"_someStatusLabel", referenced from:
MyUITests.MyUITests.(someTest (MyUITests.MyUITests) -> () -> ()).(implicit closure #1) in MyUITests.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)If I migrate the `extern NSString * const` to a `#define` macro, things work OK. However, this loses some of the functionality you gain with an `extern NSString * const` such as `if (someStatusLabel == someStatusLabel) { ... }` constant-pointer comparison in Obj-C.
// SomeClass.h
// IMPERFECT WORKAROUND:
#define myConstantString @"Hello there!"
// SomeClass.m
// ...nothing to see here...Is Swift 2.0 unable to see and use `extern NSString * const` variables from separate modules, or is this a bug in Swift 2.0 in Xcode 7-beta5? If this is not a bug, what is a good work-around other than `#define`? Thank you for reading!