Question

I have two complete projects. One works on iPhone and the other works on iPad. I want to merge these into a Universal app.

So far the only solution I have is to rename app the classes with '_iPhone' and '_iPad' suffixes and change all references to those in the code. Then I could merge the AppDelegates and load the correct controllers at launch.

These are two very big projects so this method is going to be very time consuming. Does anyone have a better solution?

Was it helpful?

Solution

well as far as i know the only solution to do that is to create a new universal project and put your files there .. since there is a lot of share code between iPhone and iPad you can check what the device is used to running your app by check if UI_USER_INTERFACE_IDIOM()is UIUserInterfaceIdiomPad or UIUserInterfaceIdiomPhone .. and for the rename the easy way to do that to highlight the class name and select Refactor>Rename and xCode will take care about rename class name in every where you used it.

OTHER TIPS

Your drafted solution seems to be the only option I know of - curious to see other answers.

One thing though; you could actually keep two separate AppDelegates.

Within your main-implementation, you could check the device and launch either the iPad-AppDelegate or the iPhone-AppDelegate.

int main(int argc, char *argv[])
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    int retVal = 0;

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        retVal = UIApplicationMain(argc, argv, nil, @"XXXAppDelegate_iPad");
    }
    else 
    {
        retVal = UIApplicationMain(argc, argv, nil, @"XXXAppDelegate_iPhone");        
    }
    [pool release];
    return retVal;
}

In most cases however, I would advice to rethink such solution - often enough this results into inconsistencies and/or code replication. Still, I thought I should point out the option.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top