目标C - 2 .m文件用于一个.h文件? [英] Objective C - 2 .m files for one .h file?

查看:141
本文介绍了目标C - 2 .m文件用于一个.h文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,我会知道如何为一个对象类使用2个.m文件也用于一个标题(.h)

我有一个很棒的方法20000 +行,我会,这种方法独立于.m文件和其他.m文件中的其他方法。我已经完成了,但是我得到错误,方法不在一个.m文件中。我得到一个链接错误,但我可以删除链接错误,如果我删除第二个.m文件。

是否可以为一个头创建2个.m文件?



如果是,请告诉我怎么做?

解决方案

方法:您可以将您的方法分成两个不同的类别:



    pre> // - MyClass1.m
    @implementation MyClass(part1)

    @end

    // - MyClass2.m
    @implementation MyClass(part2)

    @end

    为了对称原因我定义了2个类别;当然你也需要你的类的base @implementation (即没有类别说明符)。你可以选择是否定义基础和扩展类别,或者基本和两个类别等等。


  1. 或者您可以尝试在第一个文件中包含第二个 .m 文件:

      //  -  MyClass1.m 
    @implementation MyClass

    < first part>

    #includeMyClass2.m

    @end




  2. 两者都应该有效。

    更不用说重构类的可能性,这将是最好的选择。


    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 stand alone in a .m file and the other methods in the other .m file. I have done it, but I get errors, that the methods aren not in the one .m file. I get a link error, but i can remove the link error if i delete the second .m file.

    Is it possible to create 2 .m files for one header ?

    If yes pleas tell me how?

    解决方案

    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
      
          <first part>
      
          #include "MyClass2.m"
      
          @end
      

    Both should work.

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

    这篇关于目标C - 2 .m文件用于一个.h文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆