Class Method Suppression Not Found Warnings in Xcode

I have a class whose methods are defined at runtime, as stated in my question here . This works fine, but now I have a bunch of warnings that look like this: "

Class method '+objectIsNotNil:' not found (return type defaults to 'id') 

Although these warnings do not actually affect the build process, they are very annoying and make it difficult to identify the corresponding warnings. Is there a way to disable them, but only for the Assert class (maybe some kind of macro)? If this is not possible, is there a way to disable them for the entire assembly?

+6
source share
3 answers

One option is to use the performSelector: withObject: function instead of calling the method directly. Therefore, instead of:

 [Assert objectIsNotNil:object]; 

You may have:

 [Assert performSelector:@selector(objectIsNotNil:) withObject:object]; 

This does not look so good, but it will remove the warnings. In addition, this template will work for any selector you want. To make things look a little better, you can use macros as follows:

 #define ASSERT_PRECONDITION(sel, obj) [Assert performSelector:@selector(sel) withObject:obj] 

So your assert will look like this:

 ASSERT_PRECONDITION(objectIsNotNil:, object); 
+9
source

these cases should be extremely rare ...

I declared a hidden protocol that declared methods with corresponding signatures. β€œHidden” in the sense that it was included only in the translations they needed.

 @protocol MONRuntimeClassInterface + (BOOL)objectIsNotNil:(id)object; @end 
+2
source

Easy answer:

You do not want to do this. And if I understand your problem correctly, you do not need it. You define all the relevant methods in your Predicate class, described in the link, and Assertion simply redirects them. Including Predicate.h and making sure everything declared in the interface should work fine. Like methods called objects typed by id , the compiler will consider methods called the Class object that will be found if it knows at least one class in this compilation unit that implements a class method with the same name.

Alternative answer:

If you really want to suppress compiler warnings, for example, if you call a method that does not exist anywhere at compile time, you need to use the NSObject performSelector: method or the objc_msgSend() runtime objc_msgSend() . This will not be checked against the method at compile time. However, for some types of C that you could plausibly pass as arguments (float and some larger structures), the compiler must know their type. In the absence of a method definition, he needs information. performSelector: only works by accepting type identifier objects. objc_msgSend requires casting, passed to the function with the appropriate signature before calling it (and in some cases, replacing it with the option function). Mike Ash explains well how it works here .

+1
source

Source: https://habr.com/ru/post/896360/


All Articles