nhgrif
nhgrif

Reputation: 62062

How can I enforce a compiler warning or error for namespace conflicts?

Consider I have the following:

How can I get Xcode to generate either a warning or error on any line that makes references to Foo without using the namespace qualifier?

For example:

let a = FrameworkA.Foo() // fine, no warning or error
let b = FrameworkB.Foo() // fine, no warning or error
let c = Foo()            // at a minimum, a warning

I understand completely that if we are in FrameworkA, then the third example is equivalent to FrameworkA.Foo(), but I would like for Xcode to generate a warning or error.

Consider the scenario when class Foo has existed in FrameworkB for a long time, and the line of code in question has always intended to point at the class Foo defined in FrameworkB, but at some later point in the future, someone added class Foo into FrameworkA for some reason. This would change the behavior of the line in the file.

I would like Xcode to generate compile time warnings or errors any time something defined in multiple frameworks imported into a file is used without the namespace being explicitly declared.

Is there a way?

Upvotes: 14

Views: 291

Answers (1)

Zorayr
Zorayr

Reputation: 24942

I don't think at this point Xcode supports this unfortunately - some less fruitful solutions:

  • Open a radar task, and hope that Apple fixes it.
  • Prefix your classes (as we used to do with Obj-C)

The second option should be viable for most projects; instead of Foo and Foo, you will have LIBAFoo, LIBBFoo, but in practice, with more meaningful prefixes i.e. CACore Animation.

Upvotes: 2

Related Questions