Xcode 11.4 beta 在@Published 属性订阅上崩溃.这是怎么回事? [英] Xcode 11.4 beta crash on @Published property subscription. What's going on?

查看:18
本文介绍了Xcode 11.4 beta 在@Published 属性订阅上崩溃.这是怎么回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道为什么,但我的代码在这个 $searchTerm 发布者上崩溃了.我的代码中有很多这样的发布者,其他一切正常.它只在这个新的 Xcode 版本中不起作用,而在以前的版本中起作用.如果我评论了这一行并用 _searchTerm.projectedValue 替换它,它就会像往常一样开始工作!

I do not know why but my code crashes on this $searchTerm publisher. I have many such publishers in my code and everything else works ok. It only does not work in this new Xcode version and works in previous version. If I commented this line and replace it with _searchTerm.projectedValue it starts working as usuall!

 _searchTerm.projectedValue
    //$searchTerm
        .debounce(for: .milliseconds(350), scheduler: DispatchQueue.global())
        .flatMap { term in
            self.search(by: term)
        }
        .print("searching")
        .receive(on: DispatchQueue.main)
        .assign(to: \.results, on: self)
        .store(in: &disposables)

我有错误

致命错误:调用已删除的方法

Fatal error: Call of deleted method

推荐答案

如果 searchTerm 是在您的类或其超类中声明的内容,则将其标记为 final.根据我的经验,这始终可以解决此问题.

If searchTerm is something declared in your class or its superclass then mark it as final. In my experience this fixes this issues all the time.

我的理论是 Swift 无法从查找表中找出 $searchTerm 指的是哪个字段,因此崩溃.其中,将其标记为 final 将使其静态调度.我不确定这是否属实,如果有人对主题有更多了解,请发表评论,我会更新我的答案.

My theory is that Swift can't figure out which field from lookup tables is $searchTerm is referring, hence the crash. Where as, marking it as final will make it dispatch statically. I'm not sure whether this is actually true or not, if anyone has more knowledge on subject please make a comment and I'll update my answer.

这篇关于Xcode 11.4 beta 在@Published 属性订阅上崩溃.这是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆