可以将约束添加到方法

发布于 2025-01-24 13:20:47 字数 1042 浏览 3 评论 0原文

我正在尝试为Coredata更改创建出版商。

我已经实施了发布者协议,因此我被要求以同一类型实现NSfetchedResultScontrollerDelegate(不扩展)。

接下来,我需要为不同的输出实现不同的NSFetchedResultScontrollerDelegate方法。

但是,当我将约束添加到方法中时,Xcode告诉它不是协议方法,而是“几乎匹配可选要求”,并且此方法未调用。

func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) 
    where Output == [T]
{

}

func controller(
    _ controller: NSFetchedResultsController<NSFetchRequestResult>,
    didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference)
    where Output == PublishedSnapshot
{

}

我无法在没有任何条件的情况下实现这两种方法,因为``````controller(:didchangecontent with)掩盖了所有其他委托方法。

根据输出类型,我该怎么做才能实现不同的方法?

I'm trying to create a publisher for CoreData changes.

I've implemented Publisher protocol and I was required to implement NSFetchedResultsControllerDelegate in same type (not in extension).

Next, I need to implement different NSFetchedResultsControllerDelegate methods for different Outputs.

But when I add constraint where to method, xcode tells that it is not protocol method but "nearly matches optional requirement" and this method not called.

func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) 
    where Output == [T]
{

}

func controller(
    _ controller: NSFetchedResultsController<NSFetchRequestResult>,
    didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference)
    where Output == PublishedSnapshot
{

}

enter image description here
enter image description here

I can't implement both methods without any conditions because ```controller(:didChangeContentWith) hides all other delegate methods.

What should I do to implement different methods depending on Output type?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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