Hamdouchi Interactive
  • Welcome
  • Mobile
  • Tech Blog
    • Swift
    • SwiftUI
  • Let's Talk

Unlocking the Power of SwiftUI:
A Tech Blog Series

Welcome to our blog series focused on the exciting world of SwiftUI! Here, we aim to share valuable insights, practical tips, and deep dives into the latest SwiftUI features and techniques. From crafting seamless user interfaces to exploring performance strategies, our articles are designed to inspire and empower developers of all levels. Stay connected as we explore the endless possibilities with SwiftUI and spark engaging discussions about building modern, efficient apps.

Explore all SwiftUI Topics

Building Your First SwiftUI App: A Step-by-Step Guide

1/12/2025

0 Comments

 
Picture
​Welcome to week two of the SwiftUI blog series! Last week, we explored why SwiftUI is a revolutionary framework. Now, it’s time to get our hands dirty and build your very first SwiftUI app. This step-by-step guide will take you through creating a simple yet functional app that displays a list of tasks.
​
By the end of this blog, you’ll have a solid understanding of how SwiftUI works and how to create a basic app from scratch.

​What We’re Building

We’ll create a Task Manager App that allows users to:
  1. View a list of tasks
  2. Add new tasks
  3. Mark tasks as complete
Step 1: Setting Up the Project
  1. Open Xcode and select File > New > Project.
  2. Choose App under the iOS section and click Next.
  3. Enter a project name like TaskManager and ensure SwiftUI is selected as the interface.
  4. Click Continue, select a folder and click Create to set up your project.
Step 2: Designing the User Interface
In SwiftUI, your app’s UI is built declaratively using views. Open the ContentView.swift file, and let’s start coding!

Add a Title
Replace the Text(“Hello, world!”) placeholder with the following:​

    
This creates a vertical stack (VStack) with a title at the top.
Add a Task List
​Next, let’s create a dynamic list to display tasks. Modify your code to include a List:

    
Here’s what’s happening:
  • @State is used to store the list of tasks.
  • ForEach dynamically creates a row for each task.
  • We use an SF Symbol (circle) as a placeholder for task status.
Add New Tasks
​Let’s add a TextField and a button to allow users to create new tasks:

    
Key Additions:
  • A TextField for user input, bound to newTask.
  • A button with an action to append the new task to the list.
  • The button is disabled when the text field is empty.​

Marking Tasks as Complete
Let’s add functionality to toggle task completion. Update the list rows to use a State for task status:

    
Step 3: Running Your App
  1. Run your app on the simulator by pressing Cmd + R or clicking the play button.
  2. Add new tasks, check off completed ones, and admire your work!​
What’s Next?

​You’ve just built a functional task manager in SwiftUI! In the coming weeks, we’ll explore state management, animations, and ways to make your apps truly stand out.

​Next week, we’ll dive deeper into SwiftUI’s layout system to understand how stacks and frames work. Stay tuned for more!
0 Comments
    Picture

    ​Mohamed Hamdouchi


    Author

    Lead iOS Engineer.
    I help develop Design System Libraries.
    Creative Thinker.
    Featured on the App Store with 4M+ downloads.

    Archives

    March 2025
    February 2025
    January 2025

    Categories

    All
    Alignment
    Binding
    EnvironmentObject
    Frames
    Grids
    Layout
    List
    Modifiers
    ObservedObject
    Overlay
    Previews
    Responsive Design
    Stacks
    State
    State Management
    StateObject
    Task Manager
    Views
    ZStack

​​COPYRIGHT © 2009 HAMDOUCHI INTERACTIVE, LLC. ​ALL RIGHTS RESERVED
  • Welcome
  • Mobile
  • Tech Blog
    • Swift
    • SwiftUI
  • Let's Talk