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:
- Each of these objects has a unique identifier as a property.
- When each object is created, it subscribes to the
NSNotificationCenter
listening for theMY_OBJECT_SELECTED
notification. - When each object is selected, it posts the
MY_OBJECT_SELECTED
notification, with its unique Id as part of theuserInfo
dictionary. - Then, when each object receives the notification, it checks to see if its id is the same as the one in the userInfo. If it is, it does nothing, but if it isn't, it sets itself to unselected.
Is this a decent approach to the problem? If not, how would you do it?