将发布者存储在AnyCancellable设置中时的错误

发布于 2025-01-27 12:25:16 字数 1677 浏览 1 评论 0原文

一些用户使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文