Every time you launch the application in the simulator, this code runs:
// 👇🏼 Create Piper Chapman each time you run the app.
.onAppear(perform: addSample)
If you are not checking for uniqueness, SwiftData will create (and save) a new version of this user every time you run the app in the simulator.
Delete the App in the Simulator
Just as you would on a physical iPhone, press and hold on the app's icon. Navigate through all the warnings and delete the app. This not only deletes the app, it also deletes SwiftData files and related supporting files.
Then launch the app again from Xcode.
Perhaps this time, you only see ONE Piper Chapman in your list?
Here's a debugging tip:
// Change this line and add a random number to Piper's name.
let user1 = User(name: "Piper Chapman", city: "New York", joinDate: .now)
// Like this 👇🏼
let user1 = User(name: "Piper \(Int.random(in: 100...999)", city: "Bath", joinDate: .now)
How does that help you? Examine the code and tell us what you see when you run the app a few times in the simulator.
Keep Coding!