Reputation: 2032
I have an object that can be selected by a user click. With the current requirements of the app, at any time, there is no more than one of these items selected at any point during app execution.
I implemented a mechanism to enforce this, as follows:
NSNotificationCenter
listening for the MY_OBJECT_SELECTED
notification. MY_OBJECT_SELECTED
notification, with its unique Id as part of the userInfo
dictionary. Is this a decent approach to the problem? If not, how would you do it?
Upvotes: 0
Views: 55
Reputation: 1043
If the object is spread all over the app,i.e. if it is a member in various classes. You can have a global object of same type and assign it to only that object which has been touched. In steps it will be like:
Upvotes: 0
Reputation: 654
It is a decent way of doing it, although it is not very efficient. The more objects you have, the more time you spend comparing IDs. The easiest way is to store your object pointers and IDs in a map table (or similar) and remember the last selected object. Whenever you select a new object, you clear the selection flag of the last selected object, then look up the new object and set its selection flag. It requires you to keep a collection of your objects, though.
The time required to update selections with this approach is independent of the number of objects you have.
Upvotes: 1