将发布者存储在AnyCancellable设置中时的错误
一些用户使用set
使用anycancellable.store(in:)
method中存储set
。错误可能发生在10%的用户中,我无法真正复制它。
这是代码的简化版本:
private var cancellables = Set<AnyCancellable>()
private func doSomeWork() {
doMoreWork() {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
service.valuesPublisher
.sink { [weak self] something in
self?.doSomeWork(something)
}
.store(in: &self.cancellables)
}
}
错误的日志如下:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x193a3cd78 __exceptionPreprocess + 220 (NSException.m:200)
1 libobjc.A.dylib 0x1ac6a1734 objc_exception_throw + 60 (objc-exception.mm:565)
2 CoreFoundation 0x193b1ab88 -[NSObject(NSObject) doesNotRecognizeSelector:] + 144 (NSObject.m:147)
3 CoreFoundation 0x1939d1988 ___forwarding___ + 1764 (NSForwarding.m:3577)
4 CoreFoundation 0x1939d0a60 _CF_forwarding_prep_0 + 96
5 libswiftCore.dylib 0x1986312fc __CocoaDictionary.lookup(_:) + 56
6 Combine 0x1aba3d5ec specialized Set._Variant.insert(_:) + 104 (<compiler-generated>:0)
7 Combine 0x1aba5a024 AnyCancellable.store(in:) + 48 (<compiler-generated>:0)
我不知道为什么会发生任何提示?
Some users are getting this error in the app when storing a Cancellable in a Set
using the AnyCancellable.store(in:)
method. The error maybe happens to a 10% of the users and I can't really replicate it.
This is a simplified version of the code:
private var cancellables = Set<AnyCancellable>()
private func doSomeWork() {
doMoreWork() {
DispatchQueue.main.async { [weak self] in
guard let self = self else { return }
service.valuesPublisher
.sink { [weak self] something in
self?.doSomeWork(something)
}
.store(in: &self.cancellables)
}
}
And the error's log is the following:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x193a3cd78 __exceptionPreprocess + 220 (NSException.m:200)
1 libobjc.A.dylib 0x1ac6a1734 objc_exception_throw + 60 (objc-exception.mm:565)
2 CoreFoundation 0x193b1ab88 -[NSObject(NSObject) doesNotRecognizeSelector:] + 144 (NSObject.m:147)
3 CoreFoundation 0x1939d1988 ___forwarding___ + 1764 (NSForwarding.m:3577)
4 CoreFoundation 0x1939d0a60 _CF_forwarding_prep_0 + 96
5 libswiftCore.dylib 0x1986312fc __CocoaDictionary.lookup(_:) + 56
6 Combine 0x1aba3d5ec specialized Set._Variant.insert(_:) + 104 (<compiler-generated>:0)
7 Combine 0x1aba5a024 AnyCancellable.store(in:) + 48 (<compiler-generated>:0)
I have no idea why this could happen, any hints?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论