Search code examples
objective-cxcodexcode4xcode4.2

In Objective-C is it possible to keep the entire class inside the .m file?


When I create new classes in x-code it breaks it into a .h and a .m file. can I ignore the .h file and implement the entire class inside the .m file? If so what are the downsides?


Solution

  • It is absolutely possible to implement the whole class in a single .m file just as it is possible to implement an entire c++ class in a .cc file. The major disadvantage is that you lose the decoupling of interface and implementation. Another major disadvantage is that you will need to repeat the same interface code in any other .m file that utilizes the class. In other words you lose the ability to simply import the .h file in any other class file.