views:

143

answers:

2

I have multiple TableViewDatasources that need to display list of objects form same pool depending of certain property. E.g.

object.flag1 is set- it will show up in TableView1
object.flag2 is set- it will show up in TableView2

The obvious way would be to have separate arrays for each TableView, But same object may appear in different arrays. Also I need to update objects very often or access all objects through same array.

How do I setup a single dictionary or array to have all objects in one structure?


To put it in another way: When table view or selection changes, application need to redraw TableViews with the new data. Application have to access the pool of objects and search through them using iterator and accessing each object and its properties.

I think that this is an expensive operation and want to avoid that. Perhaps maybe by making a global pool of objects a dictionary and exposing objects properties as dictionary fields.

So instead of iterating global pool of objects I could access global pool Dicitonary in a manner of database by selecting objects that has fields that match particular criteria.

Anyone know any example of doing that?

A: 

This sounds like a case of premature optimization. Unless you are managing many hundreds of items and/or causing redraws to happen terribly often, iterating through even a hundred objects and maintaining a couple of arrays isn't going to incur enough overhead -- either memory or CPU -- to be problematic.

Implement it the easy way, then measure it to determine if you really have a performance problem.

bbum
A: 

I'd be inclined to create proxy collections which act as the data sources. These proxies gather the appropriate objects from the pool when they prepare their content. Without knowing the scale of your pool and subsets, it's too early to consider optimising that.

Graham Lee