|
I’d like to model a collection of Stereoview cards in SwiftData, but I don’t think I quite have the hang of things yet. Each card can have more than one title and more than one author, etc (the data came from the NY Public Library and was originally stored in a Library of Congress metadata format). So I figured I’d make a model for Card, one for Author, and one for Title, and set up some relationships. Every card should have at least one author and one title, but possibly more. And many cards could have the same author, title, etc. I’ve set up some sample data, and am trying to use Previews to sort out a layout. It all seemed to go fine the first time, but now 80% of the time I get an error: Which seems to suggest I’ve set up the relationships between my models incorrectly. Any suggestions on how to best set this up, and/or what I got wrong? My models:
And the sample data function:
|
|
It appears that the |
|
On closer inspection, I think it was having two inverses pointing to the same thing (cards) 🤦
|
|
It sounds like you're on the right track with modeling your collection of Stereoview cards in SwiftData, but the error you're encountering suggests there might be issues with your model relationships. Without seeing your code, it's a bit tricky to pinpoint the exact problem, but it's possible that the way you've defined your relationships between the Card, Author, and Title models might need adjustment. Make sure you've correctly set up the relationships to reflect that each card can have multiple authors and titles, and that each author and title can be associated with multiple cards. Double-check your model definitions and the way you're setting up these relationships to ensure they align with your data structure and intended functionality. If you're still having trouble, feel free to share some code snippets or more details about your implementation, and we can try to provide more targeted advice! by the way today egg rate is 1$ |
SPONSORED Alex is the iOS & Mac developer’s ultimate AI assistant. It integrates with Xcode, offering a best-in-class Swift coding agent. Generate modern SwiftUI from images. Fast-apply suggestions from Claude 3.5 Sonnet, o3-mini, and DeepSeek R1. Autofix Swift 6 errors and warnings. And so much more. Start your 7-day free trial today!
Sponsor Hacking with Swift and reach the world's largest Swift community!
You need to create an account or log in to reply.
All interactions here are governed by our code of conduct.
Link copied to your pasteboard.