Universal Apps In Xcode

DAMIAN ROBINSONDAMIAN ROBINSON
2 min read

Step 1: Create a new project

  1. Open Xcode and select "Create a new Xcode project."

  2. Select the "App" template and click "Next."

  3. Choose the type of app you want to create (e.g., "iOS" or "iPadOS") and select "Universal" for "Devices."

  4. Click "Next," name your project, and choose a location to save it.

  5. Click "Create" to create your project.

Step 2: Configure project settings

  1. Select your project from the Project Navigator (the left panel in Xcode).

  2. Select your project's target from the Targets list.

  3. Under the "General" tab, set the "Devices" option to "Universal."

  4. Set the "Deployment Info" section to support all desired devices, such as iPhones, iPads, or Macs.

  5. Set the "Main Interface" to the appropriate storyboard or xib file.

Step 3: Add device-specific assets

  1. Select your project from the Project Navigator.

  2. Click the "+" button under the "Assets" folder to add a new asset catalog.

  3. Click the "+" button again to add a new image set.

  4. Choose the appropriate device from the "Device" dropdown menu (e.g., "iPhone" or "iPad").

  5. Add your device-specific assets to the image set (e.g., "icon-60@2x.png" for iPhone 6/7/8 and "icon-83.5@2x.png" for iPad Pro).

Step 4: Configure your code

  1. Create a new file or modify existing code to support multiple devices.

  2. Use conditional statements to check the device type and execute code accordingly. For example:

if UIDevice.current.userInterfaceIdiom == .phone {
    // execute code for iPhones
} else if UIDevice.current.userInterfaceIdiom == .pad {
    // execute code for iPads
} else if UIDevice.current.userInterfaceIdiom == .mac {
    // execute code for Macs
}

Step 5: Test your app

  1. Build and run your app on different devices to test its functionality and appearance.

  2. Use Xcode's device simulator or connect physical devices to your computer to test your app.

  3. Make adjustments as needed to ensure your app works as expected on all devices.

Congratulations! You have now set up an Xcode project for a universal app!

0
Subscribe to my newsletter

Read articles from DAMIAN ROBINSON directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

DAMIAN ROBINSON
DAMIAN ROBINSON