Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>While Carl is correct, that is almost assuredly exactly what you don't want to do.</p> <p>Namely, it is exceptionally rare in Cocoa or iOS to pass values by reference with the purpose of updating them remotely. Beyond being fragile and error prone, it is also generally a violation of encapsulation, a fundamental OO principal.</p> <p>Given context, it sounds like you are doing some kind of a baseball sort of app? Assuming so.</p> <p>Thus, you have a <code>Lineup</code> class whose instances represent a lineup within a Team (maybe even a Team class whose instances represent individual teams) with each team managing a lineup of <code>Player</code> instances.</p> <p>So, you might have something like:</p> <pre><code>@interface Lineup:NSObject - (BOOL) substitutePlayer: (Player *) sub; @end </code></pre> <p>And you might call it like this:</p> <pre><code>- (void)handleResult:(Result)result forPlayer:(Player *)player inLineup:(Lineup *)lineup { ... handle substituion ... [lineup substitutePlayer: player]; } </code></pre> <p>And you might implement the <code>substitutePlayer:</code> as:</p> <pre><code>- (BOOL) substitutePlayer: (Player *) playerToReplace; { NSUInteger *index = [self.players indexOfObject: playerToReplace]; [self.players replaceObjectAtIndex: index withObject: [self.substitutes objectAtIndex: 0]]; [self.substitues removeObjectAtIndex: 0]; return YES; } </code></pre> <p>By doing this, you avoid the goofy <code>(Player **)</code> stuff and you encapsulate all the lineup manipulation inside of the lineup class. If you were ever to need to specialize the lineup -- say, <code>-substitutePlayer:</code> should use the last guy in <code>self.substitutes</code> -- you could subclass <code>Lineup</code> and do so.</p> <p>End result; much cleaner OO design, much easier to maintain code, and much less fragile patterns.</p> <p>(Fixed some stupid bugs due to coding in SO's edit window.)</p>
    singulars
    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