Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The dictionary approach would be easily doable. Assuming the various managers have been boiled down to specific instances when you create the dictionary, it'd be just the same as almost any object-oriented language:</p> <pre><code>NSDictionary *stringsToManagers = [NSDictionary dictionaryWithObjectsAndKeys: @"coin-large", gameLayer.coinLargeMgr, @"coin-small", gameLayer.coinSmallMgr, nil]; // this is assuming that type may contain multiple types; otherwise // just use [stringsToManagers objectForKey:string] for(NSString *string in [stringsToManagers allKeys]) { if([type rangeOfString:string].location != NSNotFound) { [[stringsToManagers objectForKey:string] addNewObject]; // or get it and store it wherever it should go } } </code></pre> <p>If all the managers do is vend appropriate objects, the more object-oriented approach might be:</p> <pre><code>NSDictionary *stringsToClasses = [NSDictionary dictionaryWithObjectsAndKeys: @"coin-large", [LargeCoin class], @"coin-small", [SmallCoin class], nil]; // this is assuming that type may contain multiple types; otherwise // just use [stringsToManagers objectForKey:string] for(NSString *string in [stringsToManagers allKeys]) { if([type rangeOfString:string].location != NSNotFound) { id class = [stringsToManagers objectForKey:string]; id newObject = [[class alloc] init]; // this is exactly the same as if, for example, you'd // called [[LargeCoin alloc] init] after detecting coin-large // within the input string; you should obviously do something // with newObject now } } </code></pre> <p>That could save you having to write any managers if your program structure otherwise fits.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload