3

I wanted to use

 for (TBL_CardView *cardView in cardsInHand)
    {
        // <#statements#>
    }

TBL_CardView is my custom class, and cardsInHand is just (TBL_CardViewArray*)

So I need to implement countByEnumeratingWithState:objects:count: for my TBL_CardViewArray class.
Is this correct ?

This is my TBL_CardViewArray.h

/**
 *    Keep TBL_CardView in array
 */
@interface TBL_CardViewArray : NSObject

- (TBL_CardView *)drawCard;
- (void)addCard:(TBL_CardView *)card;
- (NSUInteger)cardsRemaining;
- (NSArray*) cardViewArray;

- (TBL_CardView *)drawRandomCard;

@end 

Some important part from TBL_CardViewArray.m

@implementation TBL_CardViewArray
{
    NSMutableArray *_cards;
}

So I am just using TBL_CardViewArrayas s wrapper around NSMutableArray for storing my TBL_CardViewclass.

Question
How to implement countByEnumeratingWithState:objects:count: for my TBL_CardViewArray class.

I did google it, but not found some example that I could reuse easy.
My assumption is that because I am already using NSMutableArray for storing that it is not so complicated, but I can not figure it how ?

4

1 に答える 1

7

簡単に言えば、それを下層に転送しますNSMutableArray:

- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])stackbuf count:(NSUInteger)len {
    return [_cards countByEnumeratingWithState:state objects:stackbuf count:len];
}

列挙中に配列を変更しないようにする必要があります。

于 2014-07-13T12:56:15.917 に答える