Consider I have the following:
FrameworkA
, which defines class Foo
FrameworkB
, which also defines class Foo
FrameworkA
which imports FrameworkB
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?
You can request many specific warnings with options beginning with ' -W ', for example -Wimplicit to request warnings on implicit declarations. Each of these specific warning options also has a negative form beginning ' -Wno- ' to turn off warnings; for example, -Wno-implicit .
Compiler warnings are messages produced by a compiler regarding program code fragments to be considered by the developer, as they may contain errors. Unlike compilation errors, warnings don't interrupt the compilation process.
You can make all warnings being treated as such using -Wno-error. You can make specific warnings being treated as such by using -Wno-error=<warning name> where <warning name> is the name of the warning you don't want treated as an error. If you want to entirely disable all warnings, use -w (not recommended).
You can do this by specifying Werror=warning-name , which will cause that specific warning to generate an error. For example, a warning that I promote to an error is -Wreturn-type .
I don't think at this point Xcode supports this unfortunately - some less fruitful solutions:
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. CA → Core Animation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With