Project 1: Task Manager with SwiftData

IOS Development 20 min min read Updated: Nov 16, 2026 Intermediate
Project 1: Task Manager with SwiftData
Intermediate Topic 1 of 4

What We Build

  • Add, edit, complete and delete tasks
  • Priority and due date
  • Filter: All, Open, Done
  • Search by title
  • Data saved automatically with SwiftData
Requirements: Xcode with the iOS App template, SwiftUI interface and Storage set to SwiftData or None (we add it by hand). Minimum iOS 17.

1. Models

swift import SwiftData import Foundation enum Priority: Int, Codable, CaseIterable, Identifiable { case low, medium, high var id: Int { rawValue } var title: String { switch self { case .low: "Low" case .medium: "Medium" case .high: "High" } } var symbol: String { switch self { case .low: "arrow.down.circle" case .medium: "equal.circle" case .high: "exclamationmark.circle.fill" } } } @Model final class TodoTask { var title: String var notes: String var isDone: Bool var priority: Priority var dueDate: Date? var createdAt: Date init(title: String, notes: String = "", priority: Priority = .medium, dueDate: Date? = nil) { self.title = title self.notes = notes self.isDone = false self.priority = priority self.dueDate = dueDate self.createdAt = .now } }

2. App Entry

swift import SwiftUI import SwiftData @main struct TodoApp: App { var body: some Scene { WindowGroup { TaskListView() } .modelContainer(for: TodoTask.self) } }

3. The List Screen

swift import SwiftUI import SwiftData enum TaskFilter: String, CaseIterable, Identifiable { case all = "All", open = "Open", done = "Done" var id: Self { self } } struct TaskListView: View { @Environment(\.modelContext) private var context @Query(sort: \TodoTask.createdAt, order: .reverse) private var tasks: [TodoTask] @State private var filter: TaskFilter = .all @State private var search = "" @State private var editing: TodoTask? @State private var showingNew = false private var visibleTasks: [TodoTask] { tasks.filter { task in switch filter { case .all: true case .open: !task.isDone case .done: task.isDone } } .filter { search.isEmpty || $0.title.localizedCaseInsensitiveContains(search) } } var body: some View { NavigationStack { List { Picker("Filter", selection: $filter) { ForEach(TaskFilter.allCases) { Text($0.rawValue).tag($0) } } .pickerStyle(.segmented) .listRowBackground(Color.clear) ForEach(visibleTasks) { task in TaskRow(task: task) .contentShape(Rectangle()) .onTapGesture { editing = task } .swipeActions(edge: .leading) { Button(task.isDone ? "Reopen" : "Done", systemImage: "checkmark") { withAnimation { task.isDone.toggle() } } .tint(.green) } .swipeActions(edge: .trailing) { Button("Delete", systemImage: "trash", role: .destructive) { context.delete(task) } } } } .overlay { if visibleTasks.isEmpty { ContentUnavailableView("No tasks", systemImage: "checklist", description: Text("Tap + to add your first task.")) } } .navigationTitle("Tasks") .searchable(text: $search) .toolbar { Button("Add", systemImage: "plus") { showingNew = true } } .sheet(isPresented: $showingNew) { TaskEditor(task: nil) } .sheet(item: $editing) { TaskEditor(task: $0) } } } } struct TaskRow: View { let task: TodoTask var body: some View { HStack(spacing: 12) { Image(systemName: task.isDone ? "checkmark.circle.fill" : "circle") .foregroundStyle(task.isDone ? .green : .secondary) .font(.title3) VStack(alignment: .leading, spacing: 2) { Text(task.title) .strikethrough(task.isDone) .foregroundStyle(task.isDone ? .secondary : .primary) if let due = task.dueDate { Text(due, format: .dateTime.day().month().hour().minute()) .font(.caption) .foregroundStyle(due < .now && !task.isDone ? .red : .secondary) } } Spacer() Image(systemName: task.priority.symbol) .foregroundStyle(task.priority == .high ? .red : .secondary) } } }

4. Add and Edit Sheet

swift struct TaskEditor: View { @Environment(\.modelContext) private var context @Environment(\.dismiss) private var dismiss let task: TodoTask? @State private var title = "" @State private var notes = "" @State private var priority: Priority = .medium @State private var hasDueDate = false @State private var dueDate = Date.now.addingTimeInterval(3600) var body: some View { NavigationStack { Form { Section { TextField("Title", text: $title) TextField("Notes", text: $notes, axis: .vertical).lineLimit(3...6) } Section { Picker("Priority", selection: $priority) { ForEach(Priority.allCases) { Text($0.title).tag($0) } } Toggle("Due date", isOn: $hasDueDate.animation()) if hasDueDate { DatePicker("When", selection: $dueDate) } } } .navigationTitle(task == nil ? "New task" : "Edit task") .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Cancel") { dismiss() } } ToolbarItem(placement: .confirmationAction) { Button("Save", action: save) .disabled(title.trimmingCharacters(in: .whitespaces).isEmpty) } } .onAppear(perform: load) } } private func load() { guard let task else { return } title = task.title notes = task.notes priority = task.priority if let due = task.dueDate { hasDueDate = true; dueDate = due } } private func save() { let trimmed = title.trimmingCharacters(in: .whitespaces) if let task { task.title = trimmed task.notes = notes task.priority = priority task.dueDate = hasDueDate ? dueDate : nil } else { context.insert(TodoTask(title: trimmed, notes: notes, priority: priority, dueDate: hasDueDate ? dueDate : nil)) } dismiss() } }
Concept usedFrom lesson
Models and @QuerySwiftData basics
Sheets and dismissAlerts and sheets
Form, Picker, Toggle, DatePickerForms
Swipe actions and searchList and ForEach
ContentUnavailableViewLoading states

Ideas to Extend

  • Schedule a local notification at the due date
  • Add categories using a SwiftData relationship
  • Add a widget that shows today's open tasks
  • Write unit tests for the filter logic
Tip: Move the filter logic into a small struct or view model so you can unit test it.

Conclusion

You built a complete app with data, forms, filters, search and persistence. This structure is the base of many real apps.

Quick Summary: Models with @Model, @Query for reading, sheets for editing and swipe actions for quick changes make a complete task app.

Get Newsletter

Subscibe to our newsletter and we will notify you about the newest updates on Edugators