在 Xcode 12.5 上,当我尝试编译我的测试目标时,我得到了这个:
/Users/user/Development/project-ios/My ProjectTests/My ProjectTests-Bridging-Header.h:7:9: note: in file included from /Users/user/Development/project-ios/My ProjectTests/My ProjectTests-Bridging-Header.h:7:
#import "SpecHelper.h"
^
/Users/user/Development/project-ios/My ProjectTests/SpecHelper.h:36:9: note: in file included from /Users/user/Development/project-ios/My ProjectTests/SpecHelper.h:36:
#import "My_Project-Swift.h"
^
/Users/user/Library/Developer/Xcode/DerivedData/My._Project-eybfcywypdtewfbihzpxuwyltrxw/Build/Intermediates.noindex/My Project.build/Debug-iphonesimulator/My Project.build/DerivedSources/My_Project-Swift.h:98:10: error: 'SWIFT_NORETURN' macro redefined
# define SWIFT_NORETURN __attribute__((noreturn))
^
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator14.5.sdk/usr/lib/swift/shims/Visibility.h:86:9: note: previous definition is here
#define SWIFT_NORETURN __attribute__((__noreturn__))
^
<unknown>:0: error: failed to import bridging header '/Users/user/Development/project-ios/My ProjectTests/My ProjectTests-Bridging-Header.h'
Command MergeSwiftModule failed with a nonzero exit code
项目-Swift.h
#if __has_attribute(noreturn)
# define SWIFT_NORETURN __attribute__((noreturn))
#else
# define SWIFT_NORETURN
#endif
和可见性.h
#if __has_attribute(noreturn)
#define SWIFT_NORETURN __attribute__((__noreturn__))
#else
#define SWIFT_NORETURN
#endif
注意:这适用于 Xcode 12.4。
知道如何解决这个问题吗?
更新(5 月 27 日):如果我删除派生数据,运行测试套件失败并出现上述错误。尝试第二次运行它似乎有效。我不知道为什么会这样。
更新 2:(6 月 3 日):问题似乎是我在 .h 文件中定义了一个类,该类符合 swift 文件中定义的协议,不同的目标。这解释了为什么我不能使用前向声明,所以我不必导入“MyProject-Swift.h”文件。