Reputation: 9586
I have two targets in a Xcode project:
And I have many global constants with accessibility IDs in a header file in the app target that I want to use in the automation code, e.g. the header file contains:
static NSString *const APP_TUTORIAL_VIEW_ACI = @"tutorial_view";
static NSString *const APP_TUTORIAL_SCROLL_VIEW_ACI = @"tutorial_scroll_view";
but if I try to access for example APP_TUTORIAL_VIEW_ACI
in the automation Swift code it can't find it.
How do I link this so that the global constants can be used in the Swift automation target?
Upvotes: 0
Views: 400
Reputation: 9484
[YourTargetName]-Bridging-Header.h
Add your constants file in ths bridging header:
#import "ConstantsHeader.h"
Go to build settings of your Objective-C target. Search for "bridging" and copy the value from SWIFT_OBJC_BRIDGING_HEADER
You can use the constant directly now in Swift Test Target.
func testExample() { let str = APP_TUTORIAL_VIEW_ACI XCTAssert(!str.isEmpty, "str should not be empty") XCTAssert(str == "tutorial_view", "str should match") // This is an example of a functional test case. // Use XCTAssert and related functions to verify your tests produce the correct results. }
Upvotes: 1