UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

SOLVED: How to implement tree data structure in Core Data?

Forums > Swift

Hi, I am working on a project which has an internal filesystem such as nested folders and files, which requires a tree data structure, how can this be implemented in Core Data?

Thanks.

4      

The simplest approach would be to store optional parent. So this would be nil for top-level objects and upon selecting one foldermyou could query all folders whose parent is this selected one

4      

@nemecek-filip thanks for the answer but creating a relationship requires an inverse for that property, what should the inverse of parent?

3      

I think you can either have no inverse or go for one to many relationship and so the folder would have something like child folders.

4      

@nemecek-filip thanks for the help, it worked

3      

Can you please give the solution how you setup core data model and how you input data and show it to the user. I also need to do it but i'm stuck for many days I highly your help

3      

@mh175  

I am trying to do the same thing. Does this approach support reorder, insert, and delete?

4      

Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.