© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
Search
Star
Feedback
Setup for Free
SwiftData nested Lists - The Swift Den
TSD
The Swift Den
•
3y ago
•
3 replies
zko
SwiftData nested Lists
Hey
, I have two SwiftData Models and I want to create a nested list with
"ItemList
" being the parent
:
@Model
class Item
{
var name
: String
=
"
"
var completed
: Bool
= false
var repeating
: Bool
= false
var delayUntilTomorrow
: Bool
= false
var itemList
: ItemList
?
init
(name
: String
=
"
"
, completed
: Bool
= false
, repeating
: Bool
= false
, delayUntilTomorrow
: Bool
= false
)
{
self
.name
= name
self
.completed
= completed
self
.repeating
= repeating
self
.delayUntilTomorrow
= delayUntilTomorrow
}
}
AND
import Foundation
import SwiftData
@Model
class ItemList
{
var name
: String
=
"Default
"
@Relationship
(deleteRule
:
.cascade
, inverse
:
\Item
.itemList
)
var items
:
[Item
]
?
=
[
]
init
(name
: String
=
"Default
"
)
{
self
.name
= name
}
}
Recent Announcements
Similar Threads
Grouping SwiftData objects
TSD
The Swift Den / swift-development
3y ago
SwiftData and Canvas Previews confusion
TSD
The Swift Den / swift-development
3y ago
SwiftData: Value of type has no member
TSD
The Swift Den / swift-development
3y ago
Nondescript crash in my SwiftData app when trying to access a dictionary
TSD
The Swift Den / swift-development
3y ago