Skip to content

iOS Development - First Application

iOS Development with Swift - Your First Application

Section titled “iOS Development with Swift - Your First Application”

Welcome to iOS development! In this tutorial, we’ll walk through creating your very first iOS application using Xcode and Swift. We will cover:

  • Creating a New Xcode Project
  • Key Features of the Xcode IDE
  • Navigating the Xcode Interface
  • Adding a UI Label to your View
  • Running the Application on the Simulator
  • Adjusting Simulator Settings

This tutorial is designed for beginners, providing a foundational understanding of the iOS development environment.

Follow these steps to create a new project:

Step 1: Launch Xcode. On the welcome screen, select ‘Create a new Xcode project’. If Xcode is already open, you can choose File > New > Project… from the menu bar.

Step 2: In the template chooser, select the ‘iOS’ tab at the top. Choose the ‘App’ template under the ‘Application’ section, and click ‘Next’.

Step 3: You’ll now see the project options screen. Fill in the fields as follows:

  • Product Name: Enter a name for your project, e.g., ‘MyFirstApp’.
  • Team: If you have an Apple Developer account configured, select your team. For now, you can leave it as ‘None’ or your personal team if available. This is primarily for deploying apps to physical devices or the App Store.
  • Organization Identifier: Enter a reverse domain name style identifier, e.g., ‘com.yourname’. This, combined with the Product Name, creates the unique Bundle Identifier for your app (e.g., ‘com.yourname.MyFirstApp’).
  • Interface: Select ‘Storyboard’. (SwiftUI is an alternative modern UI framework, but this tutorial focuses on Storyboard/UIKit).
  • Language: Ensure ‘Swift’ is selected.
  • Storage: Select ‘None’ unless you specifically want to integrate Core Data or CloudKit from the start.
  • Include Tests: You can leave ‘Include Tests’ unchecked for this basic application.

Once all details are filled, click ‘Next’.

Step 4: Choose a location on your Mac to save the project. You can leave ‘Create Git repository on my Mac’ unchecked for now, unless you are familiar with Git. Click ‘Create’.

Congratulations! You’ve created your first iOS project.

Xcode’s interface is divided into several key areas:

  • Navigator area (left): Shows project files, issue navigator, etc. Click on Main.storyboard in the Project Navigator to open the visual design canvas for your app’s UI.
  • Editor area (center): Displays the content of the selected file (e.g., Swift code, Storyboard canvas).
  • Inspector area (right): Shows attributes and properties of the selected item (e.g., a UI element in Storyboard, or file properties). This area used to be called the Utility area.
  • Toolbar (top): Contains run/stop buttons, scheme/device selector, and view controls.
  • Debug area (bottom): Appears when running the app, showing console output and debugging tools.

Open Main.storyboard. You’ll see a representation of an iPhone screen. This is where you’ll design your app’s user interface.

Let’s add a simple text label to our view:

  • Ensure Main.storyboard is open and the View Controller scene is visible.
  • Open the Object Library: Click the ’+’ button in the toolbar, or go to View > Show Library (Shift-Command-L).
  • In the search bar of the Object Library, type ‘Label’.
  • Drag the ‘Label’ object from the library onto the center of the view in the Storyboard. Blue alignment guides will appear to help you center it.
  • Double-click the label on the Storyboard and type ‘Hello, World!’. Press Enter.
  • You can adjust the label’s properties (like font, color, text alignment) using the Attributes Inspector (looks like a slider icon) in the Inspector area on the right, after selecting the label.

Your view in the Storyboard should now display a ‘Hello, World!’ label, preferably centered.

Let’s see your app in action:

  • In the Xcode toolbar, find the scheme/device selector. It might say ‘MyFirstApp > Any iOS Device (arm64)’ or a specific simulator.
  • Click on it and choose an iPhone simulator from the list (e.g., ‘iPhone 15 Pro’).
  • Click the ‘Play’ button (a triangle icon) in the toolbar, or press Command-R. Xcode will build your app and launch it in the selected simulator.

After a few moments, the simulator will start, and you should see your app with the ‘Hello, World!’ label.

This is your final application running on the selected iPhone simulator, displaying the ‘Hello, World!’ message.

If the simulator window is too large or small for your screen:

  • With the Simulator app active, go to the menu bar at the top of your Mac’s screen.
  • Choose Window > Physical Size (Command-1), Point Accurate (Command-2), or Pixel Accurate (Command-3) to adjust the display. Older Xcode versions had a ‘Scale’ menu; modern versions offer these specific size options or allow window resizing like any other macOS app.

Explore other Simulator menus like ‘Device’ (for rotating, shaking, etc.) and ‘Features’ (for simulating location, Face ID, etc.) as you progress.

Well done! You’ve successfully created, built, and run your first iOS application. This is the starting point for building more complex and interactive apps.