0

I have a public function using a public protocol as the type of its parameter and I got the error method must be declared internal because its parameter uses an internal type. The function and the protocol are in different Swift packages(targets) under same project.

Function in Swift package A:

import B
public func func1(routeDelegate: RouteDelegate)

protocol in Swift package B:

public protocol RouteDelegate {
    func route(routeTerm: String?) -> String
}

I have added these 2 packages as each other's dependency in Package

I've been stuck here for a few hours. Any idea why the public protocol would be recognized as an internal type for parameter? Thanks!


Update: I tried to move both function and protocol in to same Swift package, and I no longer get the error. So it seems to me that while protocol is marked public, accessing it from same Swift package still makes it public, but accessing it from another Swift package would change it to be internal. Why?

  • 1
    Works for me. Try cleaning and rebuilding. – Sweeper Aug 04 '22 at 07:21
  • I tried cleaning and rebuilding it multiple times and still got same error. – user19688884 Aug 04 '22 at 07:39
  • Is your public function and protocol in the same module? If not can you try prefixing the module name. (MyModule.RouteDelegate) in the function parameter? – user1046037 Aug 04 '22 at 08:39
  • Yes they're in different Swift packages under the same project. Function is in package A, protocol is in package B. I have added these 2 packages as each other's dependency in Package – user19688884 Aug 04 '22 at 16:21

0 Answers0