ios - in Obj-C, how could I make a switch statement that will evaluate classes, rather than just numbers? -


in obj-c switch can evaluate numbers. i'd able use compare classes of objects, this, instance:

switch (currentsubviewcontroller.class)  {      case uitableviewcontroller.class :           <do stuff>           break;      case uicollectionviewcontroller.class :           <do stuff>           break; } 

is there way achieve this? i'd able use switch because makes easy read different cases, , can add more cases @ point in future. ideas?

as described in forum post better off applying liskov substitution principle , put <do stuff> logic in actual class, , call method shared superclass these classes inherit (or protocol in obj-c if you're planning have logic shared across totally different classes).

this encapsulates logic in each implementation/sub-class without higher level class needing worry every single possible implementation might have. improves maintainability , more common in object oriented programming opposed plain old procedural programming.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -