Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redundant conformance to protocol in unit test only

I have an Objective-C class in my app (MyClass). In a Swift file, I added an extension that makes it conform to the NSFilePromiseProviderDelegate protocol/interface:

extension MyClass: NSFilePromiseProviderDelegate {
    public func filePromiseProvider(_ filePromiseProvider: NSFilePromiseProvider, fileNameForType fileType: String) -> String {
        ...
    }

    public func filePromiseProvider(_ filePromiseProvider: NSFilePromiseProvider, writePromiseTo url: URL, completionHandler: @escaping (Error?) -> Void) {
        ...
    }

    public func operationQueue(for filePromiseProvider: NSFilePromiseProvider) -> OperationQueue {
        ...
    }
}

My app is compiling fine, but I have a unit test bundle (what used to be called a "Logic Test" bundle in Xcode) that also compiles all of my classes outside the app bundle. When I add the Swift file that contains this extension, I get a compiler error in my unit tests:

<path>/NSPasteboard+ACAdditions.swift:205:18: error: redundant conformance of 'MyClass' to protocol 'NSFilePromiseProviderDelegate'
extension MyClass: NSFilePromiseProviderDelegate {
                 ^
AppName.MyClass:1:11: note: 'MyClass' declares conformance to protocol 'NSFilePromiseProviderDelegate' here
extension MyClass : NSFilePromiseProviderDelegate {
          ^

It makes it look like the Swift file is somehow getting included in the unit test bundle twice, but I don't know how that would be possible. When I uncheck the unit test target from the "Target Membership" section of the File Inspector, I get other errors for classes in that file not being defined.

How do I clear this up to get my unit tests to compile again and test classes that need this file?

like image 865
Dov Avatar asked May 16 '19 13:05

Dov


1 Answers

As a workaround, I moved the class extension into a different file that's not included in the unit test bundle, since it's only required for drag-and-drop, which the tests don't touch. I'm still curious what's causing this though, and how to get this extension into my tests, in case it were something that I did want to test.

like image 149
Dov Avatar answered Oct 13 '22 00:10

Dov