45

I have a class exposing some methods, whose implementation is provided by an inner object.

I'm using forward invocation to dispatch at runtime the method calls to the inner object, but XCode is complaining since it cannot find an implementation of the declared methods.

I found some other similar questions on SO, but all of them were solved with a design change.

I don't mean to have a discussion about the design here, but if anybody has some suggestion about it I have an open question on Code Review, which is more suitable for such kind of discussions.

My question is here is whether a method to turn off the Incomplete Implementation warning in XCode exists.

Community
  • 1
  • 1
Gabriele Petronella
  • 106,943
  • 21
  • 217
  • 235

2 Answers2

79

You can suppress Incomplete Implementation warnings by adding

  #pragma clang diagnostic ignored "-Wincomplete-implementation"

just above the @implementation

Hope this helps

EDIT

After being told in the comments that this didn't work for someone and finding out the reason was because it was a different warning they were getting I have done a bit of playing around and been able to solve there issue to so I thought I would update this answer to include theirs and for GCC ignores as well. So for the issue for @Tony the following should work

  #pragma clang diagnostic ignored "-Wprotocol"

For anyone wanting to know the GCC compiler version it is

  #pragma GCC diagnostic ignored "-Wprotocol"

  #pragma GCC diagnostic ignored "-Wincomplete-implementation"

I will also make a point that all these diagnotstic ignores can also be done by specifying the setting on a per file basis by going to XCODE Project >> Target >> Build Phases >> Compile Sources and adding a compiler-flag so you would just add -Wprotocol or Wincomplete-implementation or whatever compiler-flag you needed.

Hope this update helps all if anymore need I will update my answer to include.

EDIT 2

I was doing a bit more digging around about this an came across the Clang Compliler User's Manual so I thought that this would be interesting and helpful to anyone having issues around this area still.

I have also found another way that you can use these #pragma diagnostic ignores and that is you can push and pop them so if you wanted to just ignore a particular section of the file and not all of it then you could do the following

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wmultichar"

    // And pop the warning is gone.
    char b = 'fa';

    #pragma clang diagnostic pop

Remember that all these #pragma compile ignores can be used with GCC as well so the above would

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wmultichar"

    // And pop the warning is gone.
    char b = 'fa';

    #pragma GCC diagnostic pop

The push and pop seem to work with all the diagnostic ignores I have tried so far.

Another one is

    #pragma clang diagnostic ignored "UnresolvedMessage"
    #pragma GCC diagnostic ignored "UnresolvedMessage"

The one for suppressing unused variables is

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wunused-variable"
        NSString *myUnusedVariable;
    #pragma clang diagnostic pop

and the GCC version being

    #pragma GCC diagnostic push
    #pragma GCC diagnostic ignored "-Wunused-variable"
        NSString *myUnusedVariable;
    #pragma GCC diagnostic pop

A few more for ignoring warnings from unavailableInDeploymentTarget

    #pragma clang diagnostic push
    #pragma ide diagnostic ignored "UnavailableInDeploymentTarget"
        leftEdge.barTintColor = rightEdge.barTintColor = self.toolbar.barTintColor;
    #pragma clang diagnostic pop

and performSelector leaks

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [target performSelector:cancelAction withObject:origin];
    #pragma clang diagnostic pop

and deprecated declarations

    #pragma clang diagnostic push
    #pragma clang diagnostic ignored "-Wdeprecated-declarations"
        button = [[UIBarButtonItem alloc] initWithTitle:buttonTitle style:UIBarButtonItemStyleBordered target:self action:@selector(customButtonPressed:)];
    #pragma clang diagnostic pop

Thanks to DanSkeel you can find the entire list here

Popeye
  • 11,839
  • 9
  • 58
  • 91
  • Works great, thank you. This is exactly what I asked for so I'm going to accept your answer. – Gabriele Petronella Jan 21 '13 at 18:10
  • Perfect! Thanks! Sometimes people just won't shut up. How many times can I see the same "create a category" recommendation? Yes, pragmas are generally disruptive, but this solves a lot of issues, especially when dealing with Objective C isa swizzling. – Léo Natan Mar 10 '13 at 12:28
  • Having trouble getting this to work. I'm still getting warning about it. `Method 'myMethod:' in protocol not implemented.` Any ideas? – Tony Apr 12 '13 at 17:25
  • @Tony that's a different warning. Your getting that because the protocol has either a required or optional method that needs implementing that is completely different from what this is, but I will have a look and get back to you. – Popeye Apr 12 '13 at 18:57
  • Sweet, works, thanks so much. I realized this as well shortly after the comment. I was experiencing a different kind of incomplete implementation warning. By the way, does clang diagnostic push / pop work with these? – Tony Apr 12 '13 at 21:31
  • @Tony Unfortunately I haven't tried, but first thing Monday morning I will try and get back to you. I don't see why not. I will update my answer to include response. – Popeye Apr 12 '13 at 21:47
  • One more question, is it possible to suppress warning for only a specific protocol? – Tony Feb 11 '14 at 00:17
  • @Tony I'm not entirely sure I can have a look. Which protocol? – Popeye Feb 11 '14 at 08:29
  • For example, only surpress UITableViewDelegate protocol but not surpress UITableViewDataSource protocol. – Tony Feb 12 '14 at 01:26
  • In case if you wonder, where to find [list of all warnings](http://fuckingclangwarnings.com/) – DanSkeel Aug 31 '15 at 10:12
26

You can declare the methods in a class category interface:

@interface MyClass (ForwardedMethods)

- (void)doSomething;

@end

(without an implementation for the category). Then Xcode will not complain about "incomplete implementation" anymore.

Martin R
  • 529,903
  • 94
  • 1,240
  • 1,382
  • Just like to add that this is called an informal protocol. – Nathan Day Jan 21 '13 at 18:01
  • Thank you, the informal protocol trick works great I will consider using it. – Gabriele Petronella Jan 21 '13 at 18:11
  • 2
    @GabrielePetronella: A small advantage of using an informal protocol might be that it suppresses the warnings only for the methods that you are planning to forward, and not for all methods of that class. – Martin R Jan 21 '13 at 20:28
  • I agree and it is a neat solution that I will probably use. I accepted Popeye's answer since it was exactly what I asked for, but I like the informal protocol solution as well. – Gabriele Petronella Jan 21 '13 at 20:39
  • I don't believe this works any more in the latest Xcode. – iwasrobbed Jul 06 '15 at 23:19
  • @iWasRobbed: I have checked again with Xcode 6.4 and Xcode 7 (beta 2), and it still works. – Martin R Jul 07 '15 at 07:26
  • @MartinR Thanks for checking! I was unable to do this without suppressing with pragma as a class category on a class that I owned :( – iwasrobbed Jul 07 '15 at 16:13
  • I used the same technique, and added a comment on top explaining why the implementation doesn't exist. Some people tried to "fix" the missing implementation.. – Ayush Goel May 21 '17 at 15:57