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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:54:40  来源:igfitidea点击:

How to create a .m file corresponding to a .h file in xcode

objective-cxcode

提问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 classObjective-C categoryObjective-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 classand rename the new.malone to match your old.hand remove the newly added new.hfile.
  • Create a new Objective-C classand copy your code from old.hto new.hfile
  • 您可能需要单独添加Objective-C class和重命名文件new.m以匹配您old.h并删除新添加的new.h文件。
  • 创建一个新的Objective-C class并将您的代码复制old.hnew.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 Categoriesextending the existing class methods.

您可能必须考虑使用Categories扩展现有的类方法。

What is “category

什么是“类

Customizing Existing Classes

自定义现有类

回答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 结尾
  • 点击创建保存