Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Trees #8

Closed
hfossli opened this issue Jan 15, 2016 · 4 comments
Closed

Trees #8

hfossli opened this issue Jan 15, 2016 · 4 comments

Comments

@hfossli
Copy link

hfossli commented Jan 15, 2016

Hey, I just read the readme. I like this a lot. Do you think this could be applied to trees as well? Imagine I have a tree of lightweight structs. Can I compare two trees and find the minimum changes required going from one to the other?

@osteslag
Copy link
Owner

Do you think this could be applied to trees as well?

The short answer is yes. But you probably have a little bit of work to do first…

All you have to do is to make your struct a CollectionType and implement subscripting via Int. Read more on NSHipster’s Swift Collection Protocols. You could traverse your structure recursively, like you would a file/folder hierarchy for example, and implement functions to convert between an Int and a node in your tree.

I could probably get rid of the latter requirement and rely on CollectionType’s Indexable behaviour. That would make it possible to use NSIndexPath, for example, as the index type instead of only Int, I guess, which might be a convenient way of addressing specific nodes in your tree. It would certainly be useful when using Changeset on a table/collection view data source because it would support elements moving across section boundaries out of the box.

That would be a nice improvement to Changeset, I believe, but I’ll have investigate further. I’m still a newbie when it comes to Swift.

@hfossli
Copy link
Author

hfossli commented Jan 21, 2016

Interesting. Thanks. I'll subscribe to changes on this repo and I will let you know if I got a working example.

@hfossli
Copy link
Author

hfossli commented Jan 21, 2016

Close at will

@osteslag
Copy link
Owner

You’re welcome. Will keep issue open as a reminder for me to look at the Index type stuff.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants