Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preventing protocol methods from showing up twice in autocomplete

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.


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

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

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.")
    }
}

The problem:

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.

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?


Versions:

Xcode: 7.3 (7D175)

Swift: 2.2

like image 217
xoudini Avatar asked Jul 12 '16 15:07

xoudini


Video Answer


1 Answers

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

It could be caused by:

  • duplicates originating from Xcode document updates

  • duplicates from 3rd party Xcode document plugins

  • installing two versions of Xcode side-by-side

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.

like image 124
Edison Avatar answered Sep 19 '22 19:09

Edison