xcode 如何在xcode中创建与.h文件对应的.m文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19002877/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to create a .m file corresponding to a .h file in xcode
提问by Aastha
When I try to create a .m file from the file menu, it prompts me for choosing a template from the several types mentioned - Objective-C class
, Objective-C category
, Objective-C protocol
, etc.. Which one should be preferred?
当我尝试从文件菜单中创建一个.m文件,它会提示我选择从提到的几种类型的模板- ,Objective-C class
,Objective-C category
,Objective-C protocol
等。其中一个应该是首选?
I am fairly new to Objective-C as well as Xcode, so pardon me if this question is too obvious.
我对 Objective-C 和 Xcode 还是很陌生,所以如果这个问题太明显了,请原谅我。
回答by thatzprem
- You may have to add
Objective-C class
and rename thenew.m
alone to match yourold.h
and remove the newly addednew.h
file. - Create a new
Objective-C class
and copy your code fromold.h
tonew.h
file
- 您可能需要单独添加
Objective-C class
和重命名文件new.m
以匹配您old.h
并删除新添加的new.h
文件。 - 创建一个新的
Objective-C class
并将您的代码复制old.h
到new.h
文件
Update as per comments: I see you are trying to add .m for the MAC sdk library, which is not possible.
根据评论更新:我看到您正在尝试为 MAC sdk 库添加 .m,这是不可能的。
You may have to consider using Categories
extending the existing class methods.
您可能必须考虑使用Categories
扩展现有的类方法。
回答by camilomq
If you want to create just an empty .m file, you can do so following these steps (Xcode 5.1.1):
如果您只想创建一个空的 .m 文件,您可以按照以下步骤(Xcode 5.1.1)进行操作:
- In your Xcode project, go to File --> New --> File...
- Select Other --> Empty
- Click on Next
- Type a name for your file and be sure to finish it with extension .m
- Click on Create to save it
- 在您的 Xcode 项目中,转到文件 --> 新建 --> 文件...
- 选择其他 --> 空
- 点击下一步
- 为您的文件键入一个名称,并确保以扩展名.m 结尾
- 点击创建保存