gpt4 book ai didi

ios - Swift Combine 属性继承在 Xcode 11.4 beta 2/iOS 13.4 上抛出 'Fatal error: Call of deleted method'

转载 作者:行者123 更新时间:2023-12-02 10:48:23 26 4
gpt4 key购买 nike

我正在尝试使用 Swift Combine 来获取属性的更改事件。

我有这个发布 isLogged 的类(class)属性(property)

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

@Published var isLogged: Bool = false

}

继承自发布 profileImageVersion 的其他类属性(property)
class Account {

@Published var profileImageVersion: String?

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

我正在尝试订阅已发布的继承 profileImageVersion像这样的属性(property)没有成功!
// Subscribe to account image changes
userImageChangedSubscriber = CurrentUser.me.$profileImageVersion.receive(on: DispatchQueue.main).sink(receiveValue: { (imageVersion) in
...
}
})

错误是 Fatal error: Call of deleted method
另一方面,如果我订阅 isLogged属性(property),一切正常...
// Subscribe to logged changes
userLoggedSubscriber = CurrentUser.me.$isLogged.receive(on: DispatchQueue.main).sink(receiveValue: { (logged) in
...
})

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

最佳答案

我遇到了同样的崩溃,作为临时解决方法,我发现将所有已发布的属性移动到您正在使用的具体类将解决问题。我有这样的设置:

class EpisodesViewModel {
@Published var episodes: [Episode]

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

使用这个模型的子类,它只是给出了一个获取请求:
final class LatestEpisodesViewModel: EpisodesViewModel {
init() throws {
try super.init(fetchRequest: Episode.latestFetchRequest())
}
}

通过将我的设置更改为此,我能够修复崩溃:
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())
}
}

对我来说,这当然像是一个 Apple 错误,但这同时也让我解决了这个问题。

关于ios - Swift Combine 属性继承在 Xcode 11.4 beta 2/iOS 13.4 上抛出 'Fatal error: Call of deleted method',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60464226/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com