Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift namespace conflict

Consider:

  • A Swift framework called FrameworkA that defines the type Thing.
  • A Swift framework called FrameworkB that also defines the type Thing and the type FrameworkA.
  • An app that imports both frameworks in the same Swift file.

How do I reference FrameworkA.Thing in said file? The following line fails with Thing is not a member of FrameworkA.

let t : FrameworkA.Thing? = nil
like image 560
hpique Avatar asked Nov 06 '14 07:11

hpique


People also ask

Is there namespace in Swift?

Swift modules make the need for class prefixes obsolete. Even though modules are an important step forward, they're not as flexible as many developers would want them to be. Swift currently doesn't offer a solution to namespace types and constants within modules.

What is iOS namespace?

A dynamic property type that allows access to a namespace defined by the persistent identity of the object containing the property (e.g. a view). iOS 14.0+ iPadOS 14.0+ macOS 11.0+ Mac Catalyst 14.0+ tvOS 14.0+ watchOS 7.0+


1 Answers

This appears to be a Swift bug. As a workaround, you can create a new Swift file in the app that imports only FrameworkA and defines a typealias for Thing:

import FrameworkA

typealias ThingA = Thing

Then in the file that needs to import both frameworks, you use ThingA instead of FrameworkA.Thing.

like image 86
hpique Avatar answered Sep 28 '22 11:09

hpique