Why is it NOT a compiler error to specify a protocol but not implement required methods?

You get a compiler error when the code can't be compiled. Not implementing a method doesn't prevent the code from being compiled because objective-c is a dynamic language. That means that the methods aren't directly linked, so their location doesn't need to be known at compile time. Warnings mean that there is something which could cause errors at runtime, but that the code successfully compiled.


If you want to turn this warning into an error then just add -Werror=protocol into Other Warning Flags in the Build Settings.

enter image description here


As ughoavgfhw pointed out, it's not an error because the dynamic nature of the language allows for those methods to be added at runtime. Just because the method isn't found at compile time doesn't mean it won't be there at run time.

Tags:

Objective C