I am working through the “Big Nerds Ranch” Objective-C book and noticed in one of the chapters where they are setting up an observer to listen for time zone changes they create a method in the .m file called zoneChanged however it didn’t need to be declared in the .h? How can methods be used without being declared? Is it because it was only going to be triggered by the observer?
I read that if you declare a method in the .m file then it would be private however it doesn’t seem to be declared at all in the .m file.
What they are doing is directly providing the definition itself. The problem is if it is not declared in the header file, any other file depending on this file isn’t aware that
zoneChangedfunction exist. However you can link it through the keywordexternand that is a different story.As far as to the compiler, it should know what the function is in the current compilation unit, else the compiler complains. In case if you forward declare the function, you are promising the compiler the definition is else where but may or may not be before the point of call. And if you don’t provide definition, linker complains.