Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xcode & iPhone - Best way for reusing code within multiple projects?

What is the best way to reuse code within projects?

Let's say I implemented a UI Element and I want it to be used in both my iphone and ipad application without having to copy the code over and have 2 copies of it.

like image 452
aryaxt Avatar asked Jul 05 '11 18:07

aryaxt


People also ask

What is Apple Xcode used for?

Xcode is a complete developer toolset for creating apps for Mac, iPhone, iPad, Apple Watch, and Apple TV. Xcode brings user interface design, coding, testing, debugging, and submitting to the App Store into a unified workflow.

Can Xcode run on Windows?

Given that Xcode works only on macOS, a solution to get Xcode on Windows would be to install macOS on a Windows PC by means of a virtualization app such as VMware or VirtualBox. Using a virtualization platform provides users with the full functionality of Xcode on your Windows machine.

Is Xcode for Mac free?

There are a few things I don't like about Xcode, but as a whole, it is the best totally free option for iOS development.

Is Xcode only for Mac?

Is Xcode only available on macOS? Yes. Xcode requires a Mac running macOS. At the time of writing, Xcode requires a Mac running macOS 10.15.


2 Answers

Just create a project, which includes all your shared code in XCode and reference this project in your iPhone and iPad application project. Plain and simple.

like image 99
Henrik P. Hessel Avatar answered Oct 12 '22 00:10

Henrik P. Hessel


For me I would make a static library project which contains the shared code (UI Element in your example) in Xcode.

Then when I need to use the library in the iPhone or iPad app project, then I can just reference the static library project by drag and drop the project to the Project Navigator and configure the correct dependency, library used and header search path. In this way you always have a single source of library source code for easier maintenance and modification.

Certainly you can actually compile the static library into binary and link it to your project, but it just not too flexible when you find bugs in your static library and need to switch to another project to correct the bug, and then do the compile and copy of the binary library file.

I have just wrote an article (link below) on how to link up the static library project to an iOS project on Xcode 4.3.2. This maybe useful for you to solve the header not found problem you encountered. Hope this help.

http://vicidi.wordpress.com/2012/04/11/linking-an-ios-static-library-project-in-another-project-in-xcode-4-3-2/

like image 22
VCD Avatar answered Oct 12 '22 00:10

VCD