Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode 8 says "Do you want to add a stub?" How do I answer?

Tags:

xcode8

In Xcode 8, if you declare that a class (or struct) conforms to a protocol, but haven't implemented the required methods (functions?) Xcode will give this message "Type 'ClassName' does not conform to protocol 'ProtocolName'" which is true.

If you open the error by clicking the disclosure triangle, you will see a number of items with grey exclamation mark icons. Each item says "Protocol requires function ... do you want to add a stub?" I do want to add a stub! How do I tell it to add a stub for me?

like image 735
Josh Paradroid Avatar asked Oct 04 '16 13:10

Josh Paradroid


2 Answers

The answer of raphh is right but xcode is still a little buggy here (at least for me),

If you don't select the Fix-it right after compiling the dot mark transform to exclamation mark and you can't make it appear again unless you try to build one more time.

Right after building : Dot error icon

When you don't do the Fix-it right away : exclamation mark error icon

You have to re-build to get the dot icon again when you have several methods to implement and you did do the Fix-it for the first one.

like image 68
Ysix Avatar answered Jan 12 '23 01:01

Ysix


Simply click on Fix-it and Xcode will add you the stub for that method you need to implement.

Like this. See : enter image description here

Thank you Xcode 8, finally !

like image 25
raphh Avatar answered Jan 12 '23 01:01

raphh