Skip to main content

Command Palette

Search for a command to run...

Universal Apps In Xcode

How to set up universal app projects in Xcode

Updated
2 min read
Universal Apps In Xcode

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!

Programming

Part 10 of 17

Articles and tutorials about programming and computer science concepts.

Up next

Data Structures In Swift: Fixed-Size Arrays

How to create a fixed-size array using Swift

More from this blog

Damian Robinson | Online

20 posts

The blog and business site of Damian Robinson. You will find tutorials about programming and cybersecurity, and articles pertaining to various interests or pursuits of the author.