在 xcode 中导入类文件的最佳实践

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2008194/
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-14 19:02:44  来源:igfitidea点击:

Best practices when importing class files in xcode

objective-cxcodeimportclassproject

提问by nickthedude

I'm working with xcode and I have classes associated with other projects that I want to be included in new projects. I realize that the #import will do the job technically (although what should i do if it's out of the project root folder). But what do I do if I want to include the class "properly" --basically so i can double click and edit out of the main project window where you can see all your files and such.

我正在使用 xcode,并且我有一些与我想包含在新项目中的其他项目相关联的类。我意识到#import 将在技术上完成这项工作(尽管如果它不在项目根文件夹中,我应该怎么做)。但是,如果我想“正确地”包含该类,我该怎么办——基本上,这样我就可以双击并在主项目窗口中进行编辑,您可以在其中查看所有文件等。

I guess I'm just looking for the best and/or proper way to include/import (into the project) .h and .m files that I've already created outside of the current project I'm working on. Taking into consideration that I may want to modify the class from the original without subclassing. Hopefully this makes sense.

我想我只是在寻找最好和/或正确的方法来包含/导入(到项目中)我已经在我正在处理的当前项目之外创建的 .h 和 .m 文件。考虑到我可能想修改原始类而不进行子类化。希望这是有道理的。

Thanks,

谢谢,

Nick

缺口

回答by Mr. Berna

Xcode project file organization doesn't reflect the data files on disk. Files can be added to a project from anywhere in the file system. When you add the files, choosing not to copy the files to the current project's directory means that the original files are used. Selecting one of these files in Xcode for editing will alter the original file in that other project. When returning to that other project, Xcode will use the edited files in any further work.

Xcode 项目文件组织不反映磁盘上的数据文件。文件可以从文件系统的任何地方添加到项目中。添加文件时,选择不将文件复制到当前项目的目录意味着使用原始文件。在 Xcode 中选择这些文件之一进行编辑将更改该其他项目中的原始文件。当返回到另一个项目时,Xcode 将在任何进一步的工作中使用编辑过的文件。

This type of use can be quite handy while working on multiple projects with some shared code. Yet, it can also cause headaches for a versioning system.

在使用一些共享代码处理多个项目时,这种类型的使用非常方便。然而,它也可能给版本控制系统带来麻烦。

回答by AlBlue

Might be worth thinking about how to make the classes into a private framework - then you can import that as another dependency each time. Alternatively you could use a separate version control system location to store the shared classes and just check that out into the project folder.

可能值得考虑如何将类变成私有框架 - 然后您可以每次将其作为另一个依赖项导入。或者,您可以使用单独的版本控制系统位置来存储共享类,然后将其检出到项目文件夹中。