[swift-users] What is the intended response to Array change notification for dependents?

Michael Gardner gardnermj at gmail.com
Tue Mar 7 11:28:32 CST 2017

The general approach would be to run a diff between your old and new arrays. Something like https://github.com/jflinter/Dwifft could help, though I haven't used it personally.

Another approach is to build a wrapper around your source array with limited modification methods and a KVO-like notification system. The notifications can map cleanly to UITableView updates, and there's no extra diffing calculations involved. Of course, this method won't work if your source array needs to be modified by code you don't control.

> On Mar 6, 2017, at 18:56, Edward Connell via swift-users <swift-users at swift.org> wrote:
> I would like to have an Array implementation where I get more information than just "the whole thing changed". 
> As a value type I get it, but lets say it's a list of 500 image info structs and it's bound to UI. You change one item, now the whole array changes and you have to rebuild the entire visual tree right? Rebuilding the state of dependent objects can be really expensive, not just UI things.
> Is there some efficient strategy that the library designers intended for this situation? 
> It seems like a really common and obvious scenario.
> Insights and suggestions are appreciated.
> Thanks, Ed
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users

More information about the swift-users mailing list