将Objective-C代码分割成多个文件 [英] Split Objective-C Code into multiple files

查看:129
本文介绍了将Objective-C代码分割成多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常感到需要将Objective-C代码拆分为多个文件,以提高可读性.我想避免上课并打电话给他们.我想要简单的导入(例如在php中).

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 php).

如果有人可以,请参考一个有效的示例.

If someone could please refer a working example.

推荐答案

在这种情况下,我认为您正在查看类别:

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

您要做的就是在.h文件中创建一个新的.h .m对:

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

并在.m文件中:

#import MyClass+Networking.h

@implementation MyClass(Networking)

//method definitions here

@end

在MyClass.m文件中,执行#import MyClass + Networking.h,一切就绪.这样,您可以扩展课程.

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

这篇关于将Objective-C代码分割成多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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