Swift Combine属性继承在Xcode 11.4 beta 2/iOS 13.4上引发``致命错误:已删除方法的调用'' [英] Swift Combine properties inheritance throws 'Fatal error: Call of deleted method' on Xcode 11.4 beta 2 / iOS 13.4

查看:60
本文介绍了Swift Combine属性继承在Xcode 11.4 beta 2/iOS 13.4上引发``致命错误:已删除方法的调用''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Swift Combine获得属性的更改事件.

我有发布 isLogged 属性

的此类

  class CurrentUser:帐户{静态让我= CurrentUser()//单@Published var isLogged:布尔=假} 

从另一个发布 profileImageVersion 属性

的类继承的

 类帐户{@Published var profileImageVersion:字符串?在里面(){self.profileImageVersion ="}} 

我试图像这样成功地订阅已发布的继承 profileImageVersion 属性!

 //订阅帐户图像更改userImageChangedSubscriber = CurrentUser.me.$ profileImageVersion.receive(on:DispatchQueue.main).sink(receiveValue:{(imageVersion)in...}}) 

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

另一方面,如果我订阅了 isLogged 属性,则一切运行正常...

 //订阅记录的更改userLoggedSubscriber = CurrentUser.me.$ isLogged.receive(on:DispatchQueue.main).sink(receiveValue:{(已记录)在...}) 

仅在Xcode 11.4 beta 2/iOS 13.4上引发此错误.使用Xcode 11.3.1/13.3一切正常!

解决方案

我也遇到了同样的崩溃,并且作为一种临时的解决方法,我发现将所有已发布的属性移到您正在使用的具体类上可以解决此问题.我有这样的设置:

  class EpisodesViewModel {@发表的var剧集:[第]集init(fetchRequest:NSFetchRequest< Episode> ;,上下文:NSManagedObjectContext?= nil)引发{...}...} 

具有该模型的子类,该子类仅给出了获取请求:

 最终类LatestEpisodesViewModel:EpisodesViewModel {init()引发{尝试super.init(fetchRequest:Episode.latestFetchRequest())}} 

通过将设置更改为此,我可以解决崩溃问题:

  class EpisodesViewModel {var fetchedEpisodes:[情节]init(fetchRequest:NSFetchRequest< Episode> ;,上下文:NSManagedObjectContext?= nil)引发{...}...}最终课程LatestEpisodesViewModel:EpisodesViewModel {@已发布的var剧集:[情节] = []覆盖var fetchedEpisodes:[Episode] {didSet {情节=提取情节}}init()引发{尝试super.init(fetchRequest:Episode.latestFetchRequest())}} 

在我看来,这当然像是一个Apple bug,但是与此同时,这使我得以解决这个问题.

I'm trying to using Swift Combine to get the changed event of a property.

I have this class that publish the isLogged property

class CurrentUser: Account {
    static let me = CurrentUser() //Singleton 

    @Published var isLogged: Bool = false

}

that inherit from this other class that publish the profileImageVersion property

class Account {

    @Published var profileImageVersion: String?

    init(){
       self.profileImageVersion = ""
    }
}

I'm trying to subscribe to the published inherit profileImageVersion property like this without success!

// Subscribe to account image changes
userImageChangedSubscriber = CurrentUser.me.$profileImageVersion.receive(on: DispatchQueue.main).sink(receiveValue: { (imageVersion) in           
       ...
    }
})

The error is Fatal error: Call of deleted method

if, on the other hand, I subscribe to the isLogged property, all Is working fine...

// Subscribe to logged changes
userLoggedSubscriber = CurrentUser.me.$isLogged.receive(on: DispatchQueue.main).sink(receiveValue: { (logged) in
   ...
})

This error is thrown only on Xcode 11.4 beta 2 / iOS 13.4.
Using Xcode 11.3.1 / 13.3 all is working fine!

解决方案

I have this same crash, and as a temporary workaround I found that moving all your published properties to the concrete class you are using will fix the issue. I had a setup like this:

class EpisodesViewModel {
  @Published var episodes: [Episode]

  init(fetchRequest: NSFetchRequest<Episode>, context: NSManagedObjectContext? = nil) throws {
    ...
  }
  ...
}

With a subclass of this model that simply gave a fetch request:

final class LatestEpisodesViewModel: EpisodesViewModel {
    init() throws {
        try super.init(fetchRequest: Episode.latestFetchRequest())
    }
}

By changing my setup to this I was able to fix the crash:

class EpisodesViewModel {
    var fetchedEpisodes: [Episode]

    init(fetchRequest: NSFetchRequest<Episode>, context: NSManagedObjectContext? = nil) throws {
        ...
    }
    ...
}

final class LatestEpisodesViewModel: EpisodesViewModel {

    @Published var episodes: [Episode] = []

    override var fetchedEpisodes: [Episode] {
        didSet {
            episodes = fetchedEpisodes
        }
    }

    init() throws {
        try super.init(fetchRequest: Episode.latestFetchRequest())
    }
}

This certainly seems like an Apple bug to me, but this got me around the issue in the meantime.

这篇关于Swift Combine属性继承在Xcode 11.4 beta 2/iOS 13.4上引发``致命错误:已删除方法的调用''的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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