2

Lets say I have a framework Foo that defined an open class AwesomeType. I embed that framework in my project, which unfortunately has a class named AwesomeType, too.

I read in in multiple places that Swift has implicit namespacing and that I can have the explicit name by just appending the framework's name. In my case that would be Foo.AwesomeType. That seems to work for instances of Foo.AwesomeType, but not for subclassing.

When I try to do

import Foo

public class Subclass: Foo.AwesomeType {
}

I get an error saying that AwesomeType is not a member type of Foo. When I leave out Foo, it will be referenced to the AwesomeTyp in my project, instead of that of the framwork.

How do I specify the correct type here?

  • I think I've seen this before, where if the library `Foo` contains some class also called `Foo`, then when you try to subclass using `Foo` as the name of the library, it thinks you're trying to use `Foo` as the name of the type. Is that the case here? Does the `Foo` library have a type called `Foo`? – TylerP Apr 18 '18 at 21:26
  • It does indeed! Is there any workaround for that other than renaming that the type `Foo`? I guess I could also rename the framework's name? –  Apr 18 '18 at 21:29
  • Maybe a typealias could help somehow? Like maybe `typealias FooAwesomeType = Foo.AwesomeType`? Or maybe it would still pick it up as a type instead of the framework name... Worth a try though eh? – TylerP Apr 18 '18 at 21:46
  • Unfortunately didn't help. I suppose the quickest way is to rename the framework. `FooKit`! You can create an answer and I'll accept it, as soon as I am allowed to. –  Apr 18 '18 at 21:59
  • Ahh, that's too bad! Yeah I guess renaming the framework is the best you can do, if you can. Seems like an oversight in Swift. – TylerP Apr 18 '18 at 22:17
  • 1
    `import class Foo.AwesomeType` solves the problem. – Mike Taverne Apr 19 '18 at 04:45
  • 1
    Dang. This is golden `import (class|struct|func|protocol|enum) Module.Symbol`. Thanks @MikeTaverne –  Apr 19 '18 at 09:06

0 Answers0