預警:我正在通過Itunes斯坦福大學IOS課程,而且我是一個完全使用該語言的noob。Objective C數組未存儲值
我在我的「Deck.m」文件中有這個功能。
- (id)init {
self = [super init];
if (self) {
for (NSString *suit in [Card validSuits]) {
for (NSUInteger rank = 0; rank < [[Card validRanks] count]; rank++) {
Card *card = [[Card alloc] init];
card.contents = [[[Card validRanks] objectAtIndex:rank] stringByAppendingString:suit];
[self.cards addObject:card];
NSLog(@"%@", [self.cards count]);
}
}
}
return self;
}
我也有我的「Card.h」文件這一功能(這臺由)
@interface Deck : NSObject
@property (nonatomic, strong) NSMutableArray *cards;
- (Card *)drawRandomCard;
@end
我遇到的問題是,當我打印計數運行時程序,它總是0.當我嘗試打印卡,他們看起來很好。當我嘗試通過索引數組來打印卡片時,它們都是(空)。
怎麼了?
該死的。該課程的教授明確表示要注意的確切問題。萬分感謝 – volk