[swift-users] What is the intended response to Array change notification for dependents?
Jens Alfke
jens at mooseyard.com
Tue Mar 7 09:59:19 CST 2017
On Mar 6, 2017, at 11:36 PM, Rien via swift-users <swift-users at swift.org> wrote:
> On 07 Mar 2017, at 03:56, Edward Connell via swift-users <swift-users at swift.org <mailto: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.
In Apple’s Foundation framework, Key-Value Observing (KVO) fills this need, and can be used with NSMutableArray, including when it’s bridged to Swift. But it doesn’t really transfer to a pure Swift environment since arrays are value types: changing one item is actually replacing the entire array with a new one (optimized through clever internal data-sharing.)
I would assume that the people working on the design of the Swift Foundation library are thinking about similar observer APIs, but I don’t know the details.
—Jens
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20170307/1bbc771f/attachment.html>
More information about the swift-users
mailing list