【发布时间】:2021-07-26 19:36:28
【问题描述】:
在 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
和 Visibility.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 文件中定义的协议,不同的目标。 This 解释了为什么我不能使用前向声明,所以我不必导入“MyProject-Swift.h”文件。
【问题讨论】:
-
您是否尝试删除重新定义?
-
见下文@EmilioPelaez,我不是自己添加定义,而是在“My-Project.swift”文件中生成一个,另一个似乎是模拟器中的“垫片” “../shims/Visibility.h”文件。我无法改变我所相信的。
标签: ios swift xcode ios14 xcode12.5