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

前端 未结 3 1053
日久生厌
日久生厌 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 19:09

    You can make the excessively long method a category of the class:

    MyClass.h:

    @interface MyClass
    @property ...
    -(void) method;
    ...
    @end
    
    @interface MyClass (BigMethod)
    -(void) bigMethod;
    @end
    

    MyClass.m:

    @implementation MyClass
    -(void) method
    {
        ...
    }
    ...
    @end
    

    BigMethod.m

    @implementation MyClass (BigMethod)
    -(void) bigMethod
    {
        ...
    }
    @end
    

    However, a 20k line method is absurd. You should really refactor it.

提交回复
热议问题