Combining .h and .m files

file

I have found that on one simple program, I was able to add the contents of an implementation file to the corresponding interface file, then I removed the original implementation file from the project, and everything worked fine.

Is it generally the case that the an interface and (corresponding) implementation files can be combined?

Thanks in advance for any insights.

John Doner

Best Answer

Indeed, during compilation the import directive makes the preprocessor perform the exact operation you did.

While you can glue them together, the general design is that .h files specify the outwardly visible design of the class, while the .m hides the implementation details. You could distribute the compiled code and the .h, for example, and other devs could use the class.

Keep them separated, it will be less pain all over, and in the long term it you'll appreciate the difference.