Testing a combined Objective-C / Swift application resulting in an unresolved identifier?

As mentioned in the title, this is a small combined application of Swift (mostly) and Objective-C. To provide a combination, a bridge header has been added. In particular, my problem arises when I try to test one of my Swift classes, which depends on the Objective-C class. Consider the following far-fetched application that reproduces my problem:

Expression.swift

public class Expression: NSObject {
    public func add(value: String) {
        CustomObj.doSomething()  // CustomObj is my Objective-c class
    }
}

CustomObj.h

@interface CustomObj : NSObject
+ (void) doSomething();
@end

Myapp-bridge-header.h

#import "CustomObj.h"

Merging with targeted membership occurs in two scenarios.

  • Expression.swiftbelongs MyApp only , not MyAppTests.
    • The main project compiles fine, but in tests found the control error (ExpressionTest.swift): Use of undeclared type 'Expression'.
  • Expression.swift MyApp, MyAppTests.
    • - Expression.swift: Use of unresolved identifier 'CustomObj'.

, , . , CustomObj " " → " ", ... . .

+4
1

, .

, "Objective-C Bridging Header" " " → "Swift Compiler - Code Generation". , , .

+3

All Articles