Project Setup
Personal Catalogue: iOS (Swift & SwiftUI)
Course 1 · Chapter 1 · The App and the Empty Project
This course builds a real app for your own iPhone: a catalogue of the books, CDs, DVDs and Blu-rays you own, so that standing in a shop you can answer "do I already have this?" in a few seconds. You may already have built it for the web with PHP, Django, Express or Firebase. This is the same app, rebuilt as a native iOS app in Swift with SwiftUI for the screens and SwiftData for the database. A sister course, Personal Catalogue: Android (Kotlin & Compose), builds exactly the same app with the same chapter order, so you can follow either one, or both side by side.
What We Are Building
The app has one job and a short list of features, taken from the shared spec that both mobile courses use:
| Chapter | Feature added |
|---|---|
| 1 | The empty project, folder layout, first screen in the simulator |
| 2–3 | The data model and the SwiftData store, seeded with the four item types |
| 4–5 | The list screen and the detail screen, with navigation between them |
| 6 | One add/edit form whose labels change with the item type |
| 7 | Tags: a managed, reusable list, with suggestions as you type |
| 8 | Search by title or creator, filter by tag |
| 9 | Duplicate warning, dark appearance, accessibility, error states |
| 10 | JSON backup and restore, tests, and what to build next |
The data model is small. An item has a title, a creator (author, artist or director), a "format detail" (hardcover, album, region code and so on), an optional year and some notes. Every item has one type (Book, CD, DVD or Blu-ray) and any number of tags. The app is for one person, stores everything on the phone and works with no network. Barcode scanning, cover art and cloud sync are deliberately not in this course: they are listed in the spec as later features.
How This Differs from the Web Versions
If you built a web catalogue, most of the thinking carries over and only the machinery changes:
| Web catalogue (Django, PHP, Express) | This course | |
|---|---|---|
| Language | Python, PHP or JavaScript | Swift |
| Screens | HTML templates or React components | SwiftUI View structs |
| Database | PostgreSQL, MySQL, MongoDB or Firestore on a server | SwiftData, on the phone |
| Data entry | Django admin or an HTML form | A SwiftUI Form screen |
| Server | Needed (Gunicorn, Apache, Node and so on) | None: the app is the whole system |
| Running it | A browser pointed at a URL | The iOS Simulator (on a Mac), or your own iPhone |
| Updates | Deploy and everyone sees them | Install a new build; data lives on that one phone |
The big consequence is the last two rows. There is no server and no login, so the app is simple to run but the data lives on one device. That is why Chapter 10 builds a backup file: it is the iOS equivalent of the database dump you would take from a web version.
What You Need
A Mac with Xcode. iOS apps can only be built with Xcode, which only runs on macOS. iOS Development: Fundamentals and Xcode: The IDE Itself cover installing and using it, so this chapter does not repeat that. One search source states that SwiftData needs Xcode 15.0 or later and an iOS 17.0 or later deployment target, and that apps that must support earlier versions have to use Core Data instead. That is why this course uses SwiftData with a modern minimum version.
Creating the Project
- In Xcode choose File > New > Project (or Create New Project on the welcome screen).
- Choose the iOS tab and the App template, then Next.
- Set Product Name to
Catalogue. Pick your Team (a free personal team is enough to run on a simulator or your own phone) and an Organization Identifier, such ascom.example; Xcode combines them into the bundle identifier. - Set Interface to SwiftUI and Language to Swift.
- If the dialog offers a Storage option, choose None for now. One of the search sources recommends picking SwiftData in the wizard, which makes Xcode add a starter
Itemmodel and some container code; we write our own model in Chapter 2, so we start without it. If your Xcode has no such option, or you chose SwiftData anyway, just delete the generatedItem.swiftlater when Chapter 2 replaces it. - Choose where to save it and click Create.
- Select the project in the navigator, then the Catalogue target, and look at Minimum Deployments. A forum post reports that on Xcode 16.2 the template's default was iOS 18.2, well above 17.0, so check what yours says and lower it only if you need to support older phones. Do not set it below 17.0 for this course.
What the Wizard Generated
CatalogueApp.swift is where the app starts: a struct marked @main that conforms to App and returns a WindowGroup containing the first view.
ContentView.swift holds that first view. The exact file list and the names of the test folders can differ in your Xcode.
A Folder Layout for the Whole Course
The wizard puts everything in one group. For a small app that is fine, but this one grows through ten chapters, so decide the layout now. The groups are by responsibility, the same split the web versions made between models, views and templates:
In the Project navigator, right-click the Catalogue group and choose New Group for each of Models, Data, Views (with
List, Detail and Form inside) and Backup. Groups are for organising the navigator, and may or may not match folders on disk, depending on how
your Xcode created the project; either way the layout works. Creating them now is optional: the point is to know where each thing will go.
A First Screen of Our Own
Replace the generated "Hello, world" with a screen that says what the app is. This is a sketch of the usual shape of the two generated files; yours may include a preview macro or other lines, which you should keep.
Three ideas in that code carry the whole course. A View is a Swift struct whose body describes some UI; SwiftUI calls body again whenever the data it
shows changes. A NavigationStack is the standard container for screens that push one another (the list will push the detail screen in Chapter 5), and it supplies the title bar.
A modifier such as .font(.largeTitle) is a method that wraps a view in a changed copy; you chain them, and the order matters.
Running It
- Choose a simulated iPhone from the device menu at the top of the Xcode window.
- Press Run (the play button, or Command-R). The first build and simulator start-up are slow; later ones are much faster.
- When the simulator shows My Catalogue, you have a working toolchain. The canvas preview (the
#Previewblock) shows the same screen without running the app.
To run on your own iPhone, connect it by cable, trust the computer on the phone, turn on Developer Mode in the phone's settings, and choose it in the device menu; Xcode signs the build with your personal team. If the build fails, the Issue navigator lists the errors; fix the first one before the rest, since later errors often cascade from it.
View is a composable function, a NavigationStack with a title is roughly a Scaffold with a top bar, and the iOS Simulator is the Android Emulator. The two apps end up
with the same screens and the same data model.
Challenges
Create the project as described and run it in the simulator. Write down the Product Name, Bundle Identifier, Minimum Deployment and the options your Xcode offered for Storage. Then explain in one sentence why this course needs a deployment target of iOS 17 or later.
📄 View solutionChange the screen so that it shows the app name and, underneath it, a smaller line: "Books, CDs, DVDs and Blu-rays". You will need a VStack. Run it and say which
argument controls the gap between the two lines.
Open the web catalogue course you finished (any of the four) and list, for each of the seven rows in the comparison table in this chapter, the exact file or tool you used there. Then pick the one row where iOS makes your life easier and the one where it makes it harder, and explain each in a sentence.
📄 View solutionChapter 1 Quick Reference
- The app: single-user, offline catalogue of books, CDs, DVDs and Blu-rays; items have a type, a creator, a format detail, an optional year, notes and tags
- Stack: Swift, SwiftUI, SwiftData,
@Observableview models,NavigationStack - SwiftData needs Xcode 15+ and an iOS 17+ deployment target (one source; apps for earlier versions use Core Data)
- New project: File > New > Project > iOS > App; Interface SwiftUI; Language Swift; Storage None for now
- Folder layout:
Models,Data,Views/List,Views/Detail,Views/Form,Backup - A
Viewis a struct with abody;NavigationStackholds pushed screens; modifiers chain and order matters - Run: choose a simulator, press Run (Command-R); or use your own iPhone with Developer Mode on
Item model; and one developer's report that the default
deployment target on Xcode 16.2 was iOS 18.2.Not checked, from general knowledge: the wizard's exact field names and whether your Xcode offers a Storage option with a None choice; the generated file list; the code in both files (including
#Preview and NavigationStack and that they compile together); the group layout (a design choice, not a platform rule); the simulator and Developer Mode steps;
free personal team signing; and the comparison with the Android course. Nothing was built or run. Compile it, and correct anything your Xcode does differently.
ItemType, Item and Tag classes as SwiftData models, the many-to-many link between items
and tags, and why the same decisions you made for the Django models apply here.