I started programming in C++. Because of this, I was taught early on that for each definition, there should be a declaration. With member functions, it is a requirement.
Now that I have started learning Objective-C, I was somewhat “shocked” to find out that you don’t need to pair them up. Obviously, if you don’t define a method, it will not be called. If you don’t declare a method, but define it, it will be called.
What’s the rationale for allowing this type of ad-hoc definitions? Since I’m biased by C++, I find it annoying to read other people’s code, as many times, the methods aren’t declared. It’s hard to get an overview of the class’s interface.
I found a couple of answers here: Objective c: method relation .h and .m. Unfortunately they’re not very conclusive.
Objective-C and other languages include meta-programming tooling that allows you to define methods dynamically, so you could declare a specific method and have something else define it in runtime, you can see a classic example of this feature on this question about how to implement method_missing like functionality on Objective-C.
As for the other end, having methods implemented but not declared, there’s no definite way to define private methods on Objective-C and from time to time you want to define methods that are known only to your own classes and not for everyone else. So, you don’t declare the method in your .h file, but you implement it nonetheless at your .m file.
The compiler will usually complain that you are using an undefined method, but you can either ignore this or declare these private methods at your .m file as a special category, it would look like this:
Common patterns like Proxies (local or remote ones) usually rely on these meta-programming tooling to be available and they are quite common in languages like Java, Ruby, Python and Objective-C itself.