Array extension methods are not available from other modules (for example, the XCTest project)
For simplicity, the code below does nothing, but it can be used to reproduce the error.
import Foundation extension Array { mutating func myMethod(toIndex: Int) -> Int! {
A call from the same module works as expected, but from a test class it doesnβt
class MyProjectTests: XCTestCase { func testMoveObjectsFromIndexes1() { var arr = ["000", "001", "002", "003"] arr.myMethod(0) } }
I think this is correct, because the visibility of the method is limited by its own module, indeed I get the error '[String]' does not have a member named 'myMethod'
I tried to define the extended method as public , as shown below
extension Array { public mutating func myMethod(toIndex: Int) -> Int! {
But I get a compilation error 'Extension of generic type 'Array<T>' from a different module cannot provide public declarations'
So far, beta 7 using public not solved the problem, but under Xcode 6.1 (6A1046a), I get this error
How can I fix it to work under other modules / projects?
source share