I use a nice framework called Path.swift. It imports with import Path and declares a Path struct. I went to add some SwiftUI to my code, and so added import SwiftUI. Unfortunately, SwiftUI also declares a Path struct.
var storePath: Path {…}
// ^ 'Path' is ambiguous for type lookup in this context
So I got a "'Path' is ambiguous for type lookup in this context" compile error. I tried to disambiguate it by referring to it as Path.Path, but I get the same error at the first Path.
Then I tried import struct Path.Path. Unfortunately, that doesn’t import some nice extensions, and so other code fails to compile.
Is there a way to say "Use the Path in the module Path?"
The best workaround today is to add a file to your module that only imports Path-the-module and then declare a typealias for Path-the-type. Then you can use the alias for Path.Path and also refer to SwiftUI.Path.
Alas, this doesn't seem to work. This code won't compile:
var storePath: SwiftPath {
return SwiftPath.documents / kAppDatabaseName
~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
error: binary operator '/' cannot be applied to operands of type 'DynamicPath' and 'String'
}
Path.documents returns a DynamicPath, which is struct DynamicPath : Pathish, just as struct Path : Pathish is. I’m not sure why this fails when Path.documents succeeds. / is a concatenation operator defined like this:
Oh, yes, silly me. I removed the import Path. I thought the typealias I made would magically bring along everything (e.g. PathStruct.documents would bring in DynamicPath and that would bring in the operator /, all without the need to import the module).
Nice catch. This should solve my problems. And here I went and forked their repo in order to change the name of it in their Package.swift.