How to cache data between view updates with willChange instead of didChange?

I have view A that displays data requiring some heavy computation.


Instead of redoing the computation over and over again, the data is cached every time some piece of data is modified by view B. This worked fine in beta 3, because changes triggered by view B would cause the data to:

  1. catch the didSet message
  2. update the cache
  3. send the didChange message
  4. view A (and B) was updated as a result


How can I to this in beta 4, now that willSet is used instead and it's too early to update the cache?

Accepted Reply

It turns out the solution was fairly simple:

  1. catch the willSet message
  2. set the cache to nil (i.e. defer update to when the view will be refreshed)
  3. send the willChange message
  4. the views A and B will be updated and this will repopulate the cache

Replies

Put the willChange.send() message in didSet? That is what I am doing now, but I will change it in my code.

It turns out the solution was fairly simple:

  1. catch the willSet message
  2. set the cache to nil (i.e. defer update to when the view will be refreshed)
  3. send the willChange message
  4. the views A and B will be updated and this will repopulate the cache