Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A class in Objective-C does work like an instance -- the main underlying difference is that retain counting does nothing on them. However, what you're storing in the -availableCounters array aren't instances (the <code>id</code> type) but classes, which have a type of <code>Class</code>. Therefore, with the -availableCounters definition you specified above, what you need is this:</p> <pre><code>Class counterClass = [[MyModel availableCounters] objectAtIndex: self.index]; return ( [counterClass countFor: self] ); </code></pre> <p>However, it would probably be semantically better if you used instances rather than classes. In that case, you could do something like the following:</p> <pre><code>@protocol Counter - (NSUInteger) countFor: (Model *) model; @end @interface CurrentListCounter : NSObject&lt;Counter&gt; @end @interface SomeOtherCounter : NSObject&lt;Counter&gt; @end </code></pre> <p>Then your model class could implement the following:</p> <pre><code>static NSArray * globalCounterList = nil; + (void) initialize { if ( self != [Model class] ) return; globalCounterList = [[NSArray alloc] initWithObjects: [[[CurrentListCounter alloc] init] autorelease], [[[SomeOtherCounter alloc] init] autorelease], nil]; } + (NSArray *) availableCounters { return ( globalCounterList ); } </code></pre> <p>Then your use of that would be exactly as you specified above:</p> <pre><code>id&lt;Counter&gt; counter = [[Model availableCounters] objectAtIndex: self.index]; return ( [counter countFor: self] ); </code></pre>
    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. 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