定义可产生KeyValueObservingPublisher的`publisher(for:)`方法的标头在哪里? [英] Where is the header that defines the `publisher(for:)` method that yields a KeyValueObservingPublisher?

查看:65
本文介绍了定义可产生KeyValueObservingPublisher的`publisher(for:)`方法的标头在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以看到定义了 NSObject.KeyValueObservingPublisher 的Foundation标头.但是我找不到定义返回此发布者的 publish(for:)方法的标头.而且我在文档中找不到它.

I can see the Foundation header that defines NSObject.KeyValueObservingPublisher. But I can't find the header that defines the publish(for:) method that returns this publisher. And I can’t find it in the documentation.

它必须包含NSObject,因为用KVO只能观察到NSObject.它必须以 publisher(for:) publisher(for:options:)形式出现,因为这就是Xcode提供给我的代码完成功能.但是在哪里代码完成是从那里获取信息的吗?

It must involve NSObject, because only an NSObject can be observed with KVO. And it must come in the forms publisher(for:) and publisher(for:options:), because that's what code completion offers me in Xcode. But where is code completion getting that information from?

推荐答案

它不在文档中,当您跳到标题时,它也不会在Xcode中显示.但是,我发现它隐藏在Xcode的 .swiftinterface 文件中:

It’s not in the documentation and it’s not visible in Xcode when you jump to the headers. I found it, however, hidden in a .swiftinterface file inside Xcode:

@available(OSX 10.15, iOS 13.0, tvOS 13.0, watchOS 6.0, *)
extension _KeyValueCodingAndObservingPublishing where Self : ObjectiveC.NSObject {
    public func publisher<Value>(for keyPath: Swift.KeyPath<Self, Value>, options: Foundation.NSKeyValueObservingOptions = [.initial, .new]) -> ObjectiveC.NSObject.KeyValueObservingPublisher<Self, Value>
}

因此该声明存在,但未记录在案.

So the declaration exists but it’s undocumented.

我认为这里的问题在于,此方法是在协议 _KeyValueCodingAndObservingPublishing 的扩展中声明的,该协议对于下划线在文档和生成的接口中不可见.我认为这是一个错误.

I think the problem here is that this method is declared in an extension to a protocol _KeyValueCodingAndObservingPublishing that is made invisible to the documentation and the generated interface by the underscore. I regard that as a bug.

编辑 Rob Mayoff在评论中指出,您也可以在

EDIT Rob Mayoff points out in a comment that you can also look in the source code at https://github.com/apple/swift/blob/master/stdlib/public/Darwin/Foundation/Publishers%2BKeyValueObserving.swift.

这篇关于定义可产生KeyValueObservingPublisher的`publisher(for:)`方法的标头在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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