Split Objective-C Code into multiple files

后端 未结 7 1682
猫巷女王i
猫巷女王i 2020-12-05 12:19

I often feel the need to split the Objective-C code into multiple files for better readability. I want to avoid making classes and call them. I want simple import (like in p

7条回答
  •  失恋的感觉
    2020-12-05 12:21

    I think you're looking at categories in this case:

    All you have to do is to create a new .h .m pair and in the .h file:

    #import MyClass.h
    
    @interface MyClass(Networking)
    
    //method declarations here
    
    @end
    

    and in the .m file:

    #import MyClass+Networking.h
    
    @implementation MyClass(Networking)
    
    //method definitions here
    
    @end
    

    And in MyClass.m file - do #import MyClass+Networking.h and you're all set. This way you can extend your class.

提交回复
热议问题