Reputation: 847
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)
}
In Xcode 7.3 the compiler gives me a Ambiguous use of 'sum()'. Why?
The side panel says:
Upvotes: 5
Views: 605
Reputation: 847
The problem was that I was building my Extension file both in my framework target and my test target.
Upvotes: 4