I\'m developing 2 different apps that share 95% of the same code and views. What is the best way to go about this using Xcode?
Use targets. That's exactly what they are for.
Learn more about the concept of targets here.
Typically, the majority of projects have a single Target, which corresponds to one product/application. If you define multiple targets, you can:
For example you may define Precompiler Macros for one target and other macros for the other (let's say OTHER_C_FLAGS = -DPREMIUM
in target "PremiumVersion" and OTHER_C_FLAGS = -DLITE
to define the LITE
macro in the "LiteVersion" target) and then include similar code in your source:
-(IBAction)commonCodeToBothTargetsHere
{
...
}
-(void)doStuffOnlyAvailableForPremiumVersion
{
#if PREMIUM
// This code will only be compiled if the PREMIUM macro is defined
// namely only when you compile the "PremiumVersion" target
.... // do real stuff
#else
// This code will only be compiled if the PREMIUM macro is NOT defined
// namely when you compile the "LiteVersion" target
[[[[UIAlertView alloc] initWithTitle:@"Only for premium"
message:@"Sorry, this feature is reserved for premium users. Go buy the premium version on the AppStore!"
delegate:self
cancelButtonTitle:@"Doh!"
otherButtonTitles:@"Go buy it!",nil]
autorelease] show];
#endif
}
-(void)otherCommonCodeToBothTargetsHere
{
...
}