我想用 for (TBL_CardView *cardView in cardsInHand) { // #statements# } TBL_CardView是我的自定义类,而cardsInHand只是(TBL_CardViewArray *) 所以我需要实现countByEnumeratingWithState:objects:count:用于我的TBL_CardV
for (TBL_CardView *cardView in cardsInHand) { // <#statements#> }
TBL_CardView是我的自定义类,而cardsInHand只是(TBL_CardViewArray *)
所以我需要实现countByEnumeratingWithState:objects:count:用于我的TBL_CardViewArray类.
它是否正确 ?
这是我的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
来自TBL_CardViewArray.m的一些重要部分
@implementation TBL_CardViewArray { NSMutableArray *_cards; }
所以我只是使用TBL_CardViewArrayas的NSMutableArray包装来存储我的TBL_CardViewclass.
题
如何实现countByEnumeratingWithState:objects:count:用于我的TBL_CardViewArray类.
我确实谷歌它,但没有找到一些我可以轻松重用的例子.
我的假设是因为我已经在使用NSMutableArray存储它并不是那么复杂,但我无法弄清楚如何?
- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained [])stackbuf count:(NSUInteger)len { return [_cards countByEnumeratingWithState:state objects:stackbuf count:len]; }
你必须避免在枚举时改变数组.