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?

Answered by caram in 372881022

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

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

Accepted Answer

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
How to cache data between view updates with willChange instead of didChange?
 
 
Q