weenzeel
weenzeel

Reputation: 847

Swift Ambiguous use of sum()

I have the following extension:

protocol Addable {

    init()

    func + (lhs: Self, rhs: Self) -> Self

}

extension Int: Addable {}
extension Double: Addable {}

extension SequenceType where Generator.Element: Addable {

    func sum() -> Generator.Element {

        return reduce( Generator.Element() ) { $0 + $1 }

    }

}

Which I try to use in a unit test:

func testThatArrayOfDoublesCanCalculateTheSumOfAllElements() {

    let numbers = [1.0, 2.0, 3.0]        

    let myExpectedValue = 1.0 + 2.0 + 3.0

    let myActualValue = numbers.sum()

    XCTAssertEqual(myExpectedValue, myActualValue)

}

enter image description here

In Xcode 7.3 the compiler gives me a Ambiguous use of 'sum()'. Why?

The side panel says:

enter image description here

Upvotes: 5

Views: 605

Answers (1)

weenzeel
weenzeel

Reputation: 847

The problem was that I was building my Extension file both in my framework target and my test target.

Upvotes: 4

Related Questions