防止协议方法在自动完成中显示两次 [英] Preventing protocol methods from showing up twice in autocomplete

查看:140
本文介绍了防止协议方法在自动完成中显示两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这比其他任何事情都更令人烦恼和修饰,但是Xcode中的自动完成功能存在一些一致性问题,如果有人对此有解决方案,我将非常感激.

This is more of an annoyance and cosmetic issue than anything else, but there are some consistency issues with autocomplete in Xcode, and I'd very much appreciate if somebody has a solution for it.

考虑协议MyProtocol,该协议具有属性和方法:

Consider a protocol MyProtocol, which has a property and a method:

public protocol MyProtocol {
    var variable: String { get }
    func method()
}

和采用MyProtocol并实现要求以符合协议的类A:

And a class A which adopts MyProtocol and implements the requirements in order to conform to the protocol:

public class A { ... }

extension A: MyProtocol {
    public var variable: String { get { return "String from A." } }

    public func method() {
        print("Method called.")
    }
}

问题:

访问A实例的成员时,协议方法显示两次,而属性仅显示一次:

When accessing the members of an instance of A, protocol methods show up twice, whereas properties only show up once:

如果所有内容都以代码形式记录,则很明显协议属性被隐藏,而协议方法在自动完成中仍然可见.这同样适用于协议方法的默认实现-仍然可见.

If everything is documented in code, it becomes clear that the protocol properties become hidden, while protocol methods remain visible in autocomplete. The same applies for default implementations of protocol methods - still visible.

让这个问题更加奇怪的另一件事是,例如A在声明该类的同一文件中创建,并且实例的成员也在同一文件中访问,然后协议方法从自动完成功能中消失:

Another thing that makes this issue even more peculiar is that if an instance of e.g. A is created in the same file where the class is declared, and that instance's members are accessed within the same file as well, then the protocol method disappears from autocomplete:

但是,如果从另一个文件中调用了相同的实例(现在位于全局范围内),则协议方法会重新出现在自动完成中.

But, if the same instance (which is now on the global scope) is called from another file, the protocol method reappears in autocomplete.

所以,我的问题是:有人知道如何从自动完成中隐藏重复的协议方法吗?

So, my question is: does anybody know how to hide the duplicate protocol methods from autocomplete?

版本:

Xcode: 7.3 (7D175)

Swift: 2.2

推荐答案

这似乎是一个错误. rdar://21701167 是去年提交的.

This seems to be a bug. rdar://21701167 was filed last year.

可能是由于以下原因引起的:

It could be caused by:

  • 来自Xcode文档更新的重复

  • duplicates originating from Xcode document updates

与第三方Xcode文档插件重复

duplicates from 3rd party Xcode document plugins

并排安装两个版本的Xcode

installing two versions of Xcode side-by-side

这是任何人的猜测.这有点烦人.有时我会得到3或4个重复.我使用的是Xcode的两个版本,而我使用的是第三方文档插件.

It's anyone's guess really. It is sort of annoying. Sometimes I get 3 or 4 duplicates. I am using two versions of Xcode and I was using a 3rd party document plugin.

这篇关于防止协议方法在自动完成中显示两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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