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

In Xcode 8, if you declare that a class (or structure) conforms to the protocol but did not implement the necessary methods (functions?), Xcode will provide this message โ€œTypeโ€ ClassName 'does not conform to the protocol' ProtocolName ', which is true.

If you open an error message by clicking on the disclosure triangle, you will see several items with gray exclamation point symbols. Each paragraph says, "The protocol requires a function ... do you want to add a stub?" I want to add a stub! How do I say to add a stub for me?

+7
source share
3 answers

The answer to raphh is right, but xcode is still a bit buggy (at least for me)

If you did not select Fix-it immediately after compiling the conversion of the point label to an exclamation point, and you cannot display it again if you do not try to build again.

Immediately after construction: Point Error Icon

If you don't Fix-it right away: an exclamation mark error icon

You need to rebuild to get the dot icon again when you have several methods to implement and you Fix-it for the first.

+10
source

Just hit Fix-it , and Xcode will add you a stub for this method that you need to implement.

Like it. See: enter image description here

Thanks Xcode 8 finally!

+2
source

Yes, click โ€œfix it,โ€ xcode will add the necessary methods and variables as indicated in your protocol, and one more thing, Xcode will add the variables with the appropriate read permissions to the class that implements the protocol.

For example: in your protocol, if you declare a get, set variable, and in your structure / class you declare it as a 'let' property, then Xcode will display the error message โ€œWant to add a protocol stubโ€ when you click fix it, now add the 'var' property in the protocol, while maintaining the class / structure to receive, set the property in the protocol

 protocol VoiceAssistant { var name: String {get} var voice: String {get set} } struct Siri: VoiceAssistant { var voice: String //xcode added this, when you click 'fix it' for protocol stub let name = "Siri" let voice = "Voice" //added by me, Compilation Error: voice is not settable, but protocol requires it. } 
0
source

All Articles