简体   繁体   English

管理不同Xcode项目之间共享的源文件的简单方法是什么?

[英]What's an easy way to manage source files that are shared among different Xcode projects?

I'm diving into iOS development and I plan to build a few basic apps that make use of my own reusable code. 我正在深入研究iOS开发,我计划构建一些使用我自己的可重用代码的基本应用程序。 As I update the files that contain my reusable code, I'd like those updates to be reflected in all the Xcode projects that use them. 当我更新包含我的可重用代码的文件时,我希望这些更新能够反映在使用它们的所有Xcode项目中。 What are some ways I can do this? 有什么方法可以做到这一点?

Thanks in advance for your help! 在此先感谢您的帮助!

There are a few ways you can do it. 有几种方法可以做到。

If your "reusable code" is separated into libraries, you could package it up as individual projects (that compile to static libraries) and then link them into your main project (that compiles into an executable). 如果将“可重用代码”分成库,则可以将其打包为单个项目(编译为静态库),然后将它们链接到主项目(编译为可执行文件)。 A bit tricky, but it's the "proper" way. 有点棘手,但这是“正确”的方式。 (Not as flexible or easy as Visual Studio's solution/project paradigm, but that's a rant for another day.) (不像Visual Studio的解决方案/项目范例那样灵活或简单,但这是另一天的咆哮。)

You could also just drag-and-drop a directory containing the source files into the Project window directly, either using "Create Folder References" or "Recursively create groups". 您也可以直接将包含源文件的目录拖放到Project窗口中,使用“Create Folder References”或“Recursively create groups”。 (Either way, you don't want to use the "Copy items" checkbox at the top if you want only one copy of the source files.) (无论哪种方式,如果只需要源文件的一个副本,则不希望使用顶部的“复制项目”复选框。)

I've done all three. 我已经做了三个。

You may want to start with the latter -- group your "reusable code" into a folder somewhere (so there's only one copy) and then drag-and-drop that folder into your project using "Recursively create groups". 您可能希望从后者开始 - 将“可重用代码”分组到某个文件夹(因此只有一个副本),然后使用“递归创建组”将该文件夹拖放到项目中。 One warning: if you do that in multiple projects, and sometime later you want to remove it from the project, don't use the option to send it to the trash, or your other projects could get messed up. 一个警告:如果您在多个项目中执行此操作,并且稍后您想要将其从项目中删除,请不要使用该选项将其发送到垃圾箱,否则您的其他项目可能会搞砸。

这听起来像是你可以使用Git和分支的东西。

创建一个静态库项目,然后使用Xcode的项目间依赖项功能以正确的顺序构建它们并将应用程序与静态库链接

One solution I've thought of is to build a static library project, but only use it just to test compile the reusable code in that library. 我想到的一个解决方案是构建一个静态库项目,但只是用它来测试编译该库中的可重用代码。 Then symlink the reusable source code subdirectory of that library project into all other projects that use that code. 然后将该库项目的可重用源代码子目录符号链接到使用该代码的所有其他项目中。 That way all the source code is available in any project, and any changes I make in the reusable code will be reflected everywhere else immediately (no copy step). 这样,所有源代码都可以在任何项目中使用,我在可重用代码中所做的任何更改都会立即反映在其他任何位置(无复制步骤)。 And of course, use a good source code revision control methodology on that subdirectory, so that I can version it, compare changes, revert, etc. 当然,在该子目录中使用一个好的源代码修订控制方法,以便我可以对其进行版本化,比较更改,还原等。

the proper way is to create a library. 正确的方法是创建一个库。 in iOS, you're restricted to static libraries, but dynamic libraries and frameworks are other common possibilities (for example, if you're targeting OS X). 在iOS中,您仅限于静态库,但动态库和框架是其他常见的可能性(例如,如果您的目标是OS X)。

to configure this (using libStatic as a name for the static library, and App as the app in this example): 配置它(使用libStatic作为静态库的名称,在此示例中使用App作为应用程序):

1) create the libStatic project, and configure it to compile the files you choose 1)创建libStatic项目,并将其配置为编译您选择的文件

2) add libStatic.xcodeproj to the App.xcodeproj. 2)将libStatic.xcodeproj添加到App.xcodeproj。 this adds the project symbols, indexes and references to the App project. 这会将项目符号,索引和引用添加到App项目中。

(the remaining steps all take place in App.xcodeproj) (其余步骤全部在App.xcodeproj中进行)

3) double click the target which depends on liStatic 3)双击依赖于liStatic的目标

4) navigate to General tab 4)导航到“常规”选项卡

5) click '+' under the dependencies list, and add the libStatic target to the dependencies. 5)单击依赖项列表下的“+”,并将libStatic目标添加到依赖项。 it is important that you create this association/dependency so the libStatic target will be kept up to date as you develop in App (it will be built before App). 创建此关联/依赖项非常重要,这样当您在App中开发时,libStatic目标将保持最新(它将在App之前构建)。

6) navigate to the libStatic project reference in the groups & files tree. 6)导航到组和文件树中的libStatic项目引用。 if necessary, click (expand) the disclosure triangle to view the products of libStatic. 如有必要,单击(展开)显示三角形以查看libStatic的产品。

7) drag the appropriate product from the libStatic project reference into the App target's link stage. 7)将相应的产品从libStatic项目引用拖到App目标的链接阶段。

8) clean, build, run 8)清洁,建造,运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有哪些方法可以在源代码管理中跟踪Xcode项目? - What are some methods for keeping track of Xcode projects in source control? 在iOS设备之间交换结构数据的建议方法是什么? - What's the suggested way to exchange structure data among iOS devices? 使用Xcode 4,主项目+共享代码项目的正确方法是什么? - With Xcode 4, what is the proper way have a main project + a shared code project? 在基于Xcode的iPhone应用程序中的应用程序之间重用实用程序功能的推荐方法是什么? - What is the recommended way to reuse utility functions among apps in my Xcode based iphone apps? 在XCode 4中调用segue的正确方法是什么? - What's the correct way to call a segue in XCode 4? 将Xcode项目移动到不同的计算机 - Moving Xcode Projects to different computer 2个类似的iOS应用程序-管理它们的最佳方法是什么? - 2 similar iOS apps - what's the best way to manage them? XCode 4:将 Mac 项目转换为 iOS 的简便方法? - XCode 4: Easy way to convert Mac project to iOS? 在 objective-c 的不同类之间访问/共享 object 实例的最佳方法是什么? - What is the best way to access/share object instances among different classes in objective-c? 为多个客户端处理具有相同代码库的xcode项目的最佳方法是什么? - What's the best approach to handle xcode projects with same codebase for multiple clients?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM