我有一个@Published
变量来指示我的一个存储库类中的用户状态。
@Published public var state: UserState = .initial
在测试中,我曾经sink
很容易观察到变化并满足我的测试等待的期望。
原始测试代码如下所示:
sub = Authentication.shared.$state.receive(on: DispatchQueue.main).sink(receiveValue: { state in
expectation.fulfill()
})
Authentication.shared.login(with: Credentials(email: "gujci@gmail.com", password: "asdasd"))
这导致编译器错误如下Abort trap: 6
Global is external, but doesn't have external or weak linkage!
i64* @"$s14TestRepository14AuthenticationC6_state33_B23F0E9C543FDF10733C02EF2F1E18CCLL7Combine9PublishedVyAA9UserStateOGvpWvd"
<unknown>:0: error: fatal error encountered during compilation; please file a bug report with your project and the crash log
<unknown>:0: note: Broken module found, compilation aborted!
Stack dump:
...
发生这种情况的项目与应用程序位于单独的 swift 包中。
当我尝试从应用程序中使用它时(测试中没有),结果是一样的。另外,我尝试过其他出版商,例如。Just
并Future
从网络调用返回,所有这些都与sink
.
我从 beta 4 开始就有这个问题,但在以前的版本中从未尝试过,可能也会出现在这些问题中。我注意到,在 beta 4 和 5 之间,Combine 发生了巨大的变化,但是错误仍然存在。
是否有人设法在外部库sink
中的变量上使用该函数而没有此类错误?@Published
如果我误解了某些东西,请纠正我,现在我不得不假设,问题出在 Apple 的最后。