0Day Forums
Is there a way to suppress warnings in Xcode? - Printable Version

+- 0Day Forums (https://0day.red)
+-- Forum: Coding (https://0day.red/Forum-Coding)
+--- Forum: Objective-C (https://0day.red/Forum-Objective-C)
+--- Thread: Is there a way to suppress warnings in Xcode? (/Thread-Is-there-a-way-to-suppress-warnings-in-Xcode)



Is there a way to suppress warnings in Xcode? - analcimes506591 - 07-21-2023

Is there a way to suppress warnings in Xcode?

For example I am calling an undocumented method and since the method is not in the header I get a warning on compile. I know I can add it to my header to stop the warning, but I am wondering if there is a way other than adding it to the header (so I can keep the headers clean and standard) to suppress the warning? A pragma or something?


RE: Is there a way to suppress warnings in Xcode? - paulitatpk - 07-21-2023

Suppressing that particular warning is not safe. The compiler needs to know the types of the arguments and returns to a method to generate correct code.

For example, if you're calling a method like this

[foo doSomethingWithFloat:1.0];

that takes a float, and there is no prototype visible, then the compiler will guess that the method takes a double, not a float. This can cause crashes and incorrectly interpreted values. In the example above, on a little endian machine like the intel machines, the receiver method would see 0 passed, not 1.

You can read why in the [i386 ABI docs](

[To see links please register here]

), or you can just fix your warnings. :-)


RE: Is there a way to suppress warnings in Xcode? - kalinlznf - 07-21-2023

With Objective-C, a number of serious errors only appear as warnings. Not only do I *never* disable warnings, I normally turn on "Treat warnings as errors" (-Werror).

Every type of warning in your code can be avoided by doing things correctly (normally by casting objects to the correct type) or by declaring prototypes when you need them.


RE: Is there a way to suppress warnings in Xcode? - Sirbibbiexah - 07-21-2023

Create a new, separate header file called 'Undocumented.h' and add it to your project. Then create one interface block for each class you want to call undocumented functions on and give each a category of '(Undocumented)'. Then just include that one header file in your PCH. This way your original header files remain clean, there's only one other file to maintain, and you can comment out one line in your PCH to re-enable all the warnings again.

I also use this method for depreciated functions in 'Depreciated.h' with a category of '(Depreciated)'.

the best part is you can selectively enable/disable individual warnings by commenting or uncommenting the individual prototypes.


RE: Is there a way to suppress warnings in Xcode? - bait161009 - 07-21-2023

In order to surpress a warning for an individual file do the following:

select the file in the xcode project.
press get info
go to the page with build options
enter -Wno- to negate a warning:

> -Wno-<your warning>

e.g.

> -Wno-unused-parameter

You can get the name of the warning if you look on the project settings look at the GCC warnings located at the bottom of the build tab page, by clicking on each warning it will tell you the warning parameter name:

e.g.

> Warn whenever a function parameter is
> unused aside from its declaration.
> [GCC_WARN_UNUSED_PARAMETER,
> -Wunused-parameter]






RE: Is there a way to suppress warnings in Xcode? - rave281048 - 07-21-2023

To get rid of the warning: try creating a category interface for the object in question

<myClass.m>

@interface NSTheClass (MyUndocumentedMethodsForNSTheClass)

-(id)theUndocumentedMethod;
@end
...

@implementation myClass : mySuperclass

-(void) myMethod {
...
[theObject theUndocumentedMethod];
...
}

As an aside, I _strongly_ advise against calling undocumented methods in shipping code. The interface can and will change, and it will be your fault.



RE: Is there a way to suppress warnings in Xcode? - visibly492137 - 07-21-2023

there is a simpler way to suppress **Unused variable** warnings:

#pragma unused(varname)


EDIT:
source:

[To see links please register here]


UPDATE:
I came accross with a new solution, a more robust one

1. Open the Project > Edit Active Target> Build tab.
2. Under `User-Defined`: find (or create if you don't find one )the key : `GCC_WARN_UNUSED_VARIABLE` set it to `NO`.

EDIT-2
Example:

BOOL ok = YES;
NSAssert1(ok, @"Failed to calculate the first day the month based on %@", self);

the compiler shows unused variable warning for `ok`.

Solution:

BOOL ok = YES;
#pragma unused(ok)
NSAssert1(ok, @"Failed to calculate the first day the month based on %@", self);

PS:
You can also set/reset other warning:
`GCC_WARN_ABOUT_RETURN_TYPE` : `YES/NO`


RE: Is there a way to suppress warnings in Xcode? - ameed790330 - 07-21-2023

[To see links please register here]

- skip to inhibiting warnings section



RE: Is there a way to suppress warnings in Xcode? - tonievgpgjsxky - 07-21-2023

To disable warnings on a per-file basis, using Xcode 3 and llvm-gcc-4.2 you can use:

#pragma GCC diagnostic ignored "-Wwarning-flag"

Where warning name is some gcc warning flag.

This overrides any warning flags on the command line. It doesn't work with all warnings though. Add -fdiagnostics-show-option to your CFLAGS and you can see which flag you can use to disable that warning.



RE: Is there a way to suppress warnings in Xcode? - behka973 - 07-21-2023

## For gcc you can use


#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wshadow-ivar"
// your code
#pragma GCC diagnostic pop

You can learn about [GCC pragma here][1] and to get the warning code of a warning go to the Report Navigator (Command+9), select the topmost build, expand the log (the '=' button on the right), and scroll to the bottom and there your warning code is within square brackets like this `[-Wshadow-ivar]`


## For clang you can use

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wshadow-ivar"
// your code
#pragma clang diagnostic pop

[1]:

[To see links please register here]