To create two different apps (like "Light" and "Regular") from the same codebase in Xcode, you can follow these steps by leveraging targets and build configurations. This allows you to create multiple versions of your app with variations such as different branding, themes, or configurations.
Step-by-Step Guide:
1. Create a New Target for the Second App
- Open your Xcode project.
- In the Project Navigator, select your project.
- Go to the Targets section and right-click on the current target (the one for the original app).
- Select Duplicate Target.
- Rename the duplicated target (e.g., "Light" or "Regular" depending on the new app version).
- Xcode will ask you to create a new scheme for the new target. Choose Yes.
2. Adjust the Target Settings
- Select the new target and change the settings (like Bundle Identifier, Display Name, etc.):
- Bundle Identifier: Ensure this is unique for the new app version (e.g.,
com.yourcompany.app.lightvs.com.yourcompany.app.regular). - Display Name: Set a different name for the app version so they can be installed side by side on devices.
- Bundle Identifier: Ensure this is unique for the new app version (e.g.,
3. Modify the Info.plist for Each Target
- You’ll need separate
Info.plistfiles for each app version.- Right-click your project in the Project Navigator, select New File, and choose Property List.
- Name it something like
Info-light.plistorInfo-regular.plist.
- Assign each
Info.plistto the corresponding target:- Select the target, go to the Build Settings tab.
- Search for Info.plist File and point it to the correct
Info.plistfor the target (e.g.,Info-light.plistfor the Light version).
4. Set Up Custom Assets (Optional)
If you have different assets (like icons, splash screens, etc.):
- Add separate asset catalogs for each version (e.g.,
Assets-light.xcassetsandAssets-regular.xcassets). - In the Build Phases of each target, include the appropriate assets for that target.
5. Conditional Compilation (Optional)
If there are code differences between the two versions (e.g., features, themes), you can use preprocessor macros in the code:
- In Build Settings, search for Other Swift Flags.
- Add flags like
-DLIGHTfor the Light target and-DREGULARfor the Regular target. - In your Swift code, you can now use:
6. Build Configurations (Optional)
If you need different build settings (e.g., debug vs. release or different environment variables):
- Go to Project Settings -> Info.
- Add new build configurations if necessary, and assign them to the correct targets.
7. Configure Schemes
- Open the Scheme Editor (Product > Scheme > Edit Scheme).
- Create a separate scheme for each target (if Xcode didn’t create them during duplication).
- Select the appropriate target and configuration for each scheme (e.g., one for Light and one for Regular).
8. Test and Build
- Now you should have two distinct apps ("Light" and "Regular") that can be built and installed side-by-side.
- Select the appropriate scheme (e.g., "Light" or "Regular") and run the app.
By using targets and schemes, you can efficiently maintain multiple apps with shared code, but with enough flexibility to customize each version.
For more details, you can refer to Xcode documentation on managing targets and schemes
No comments:
Post a Comment