ios - Sending NSNotifications to all objects of a class -


i have object can selected user click. current requirements of app, @ time, there no more 1 of these items selected @ point during app execution.

i implemented mechanism enforce this, follows:

  • each of these objects has unique identifier property.
  • when each object created, subscribes nsnotificationcenter listening my_object_selected notification.
  • when each object selected, posts my_object_selected notification, unique id part of userinfo dictionary.
  • then, when each object receives notification, checks see if id same 1 in userinfo. if is, nothing, if isn't, sets unselected.

is decent approach problem? if not, how it?

it decent way of doing it, although not efficient. more objects have, more time spend comparing ids. easiest way store object pointers , ids in map table (or similar) , remember last selected object. whenever select new object, clear selection flag of last selected object, new object , set selection flag. requires keep collection of objects, though.

the time required update selections approach independent of number of objects have.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -