Reputation: 1925
I have an entity named Group. The Group entity has a transient attribute named displayImage. This displayImage is computed on the fly. The computations involve 2 or more image rotations, scaling. and cropping. Note: the images involved in the computations are retrieved from another entity.
I have a UITableView, which displays the Group entities. In each Group cell, I display the displayImage.
The question: how can I implement it so that the displayImage is computed in the background (to avoid screen ferezes while the computation is ongoing)?
I have seen examples of displaying images asynchronously, but that involves setting the image of a UIImageView in main thread after the asynchronous call has come back. My problem is that the asynchronous call will set a transient property of an NSManagedObject.
Upvotes: 0
Views: 84
Reputation: 17208
Instead of putting it in the getter, why not do just as you've described?
When you initially load, leave the image property alone and start the background process. When it finishes, invoke a selector on the main thread to set the property value with the result.
You can use KVO or post a notification to trigger your view controller to reload the affected table cells.
Upvotes: 1