Objective C - 2 .m files for one .h file?

前端 未结 3 1060
日久生厌
日久生厌 2021-01-21 18:37

My question is, that I would know how to use 2 .m files for one objectclass also for one header (.h)

I have a big method with 20000+ lines and I would, that this method

3条回答
  •  南笙
    南笙 (楼主)
    2021-01-21 18:52

    You have several approaches:

    1. you could split your methods into 2 different categories:

      //-- MyClass1.m
      @implementation MyClass (part1)
      
      @end
      
      //-- MyClass2.m
      @implementation MyClass (part2)
      
      @end
      

      I defined 2 categories for symmetry reason; of course you also need a "base" @implementation of your class (i.e., without the category specifier); you can choose whether you define a "base" and and extension category, or "base" and two categories, etc...

    2. or you might try including the second .m file inside of the first one:

          //-- MyClass1.m
          @implementation MyClass
      
          
      
          #include "MyClass2.m"
      
          @end
      

    Both should work.

    Let alone the possibility of refactoring your class, which would be the best option.

提交回复
热议问题