开发者

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

开发者 https://www.devze.com 2023-01-14 23:18 出处:网络
I\'m diving into iOS development and I plan to build a few basic apps that开发者_运维问答 make use of my own reusable code.As I update the files that contain my reusable code, I\'d like those updates

I'm diving into iOS development and I plan to build a few basic apps that开发者_运维问答 make use of my own reusable code. 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. 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.)

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". (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.


This sounds like something you could use Git and branching for.


Create a static library project, then use the interproject dependency feature of Xcode to build them in the correct order and link the app with the static library


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

to configure this (using libStatic as a name for the static library, and App as the app in this example):

1) create the libStatic project, and configure it to compile the files you choose

2) add libStatic.xcodeproj to the App.xcodeproj. this adds the project symbols, indexes and references to the App project.

(the remaining steps all take place in App.xcodeproj)

3) double click the target which depends on liStatic

4) navigate to General tab

5) click '+' under the dependencies list, and add the libStatic target to the dependencies. 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).

6) navigate to the libStatic project reference in the groups & files tree. if necessary, click (expand) the disclosure triangle to view the products of libStatic.

7) drag the appropriate product from the libStatic project reference into the App target's link stage.

8) clean, build, run

0

精彩评论

暂无评论...
验证码 换一张
取 消