iOS 7 Matchismo任务1斯坦福问题

时间:2014-01-19 03:10:36

标签: ios objective-c ios7

我为斯坦福大学iOS7编程的iTunesU课程编写了第一份作业的代码。问题是,当我编译时,我收到一条警告,上面写着addCard的方法定义:找不到。

这是我在Deck课程中的代码。谁能告诉我我做错了什么?

#import "Deck.h"

@interface Deck()
@property(strong, nonatomic)NSMutableArray *cards;// of Card
@end

@implementation Deck

-(NSMutableArray *)cards
{
if(!_cards) _cards = [[NSMutableArray alloc] init];
return _cards;
}

-(void)addCard:(Card *)card atTop:(BOOL)atTop
{
if(atTop){
    [self.cards insertObject:card atIndex:0];
}else{
    [self.cards addObject:card];
}
}


-(void)addcard:(Card *)card
{
[self addCard:card atTop:NO];
}

-(Card *)drawRandomCard
{
Card *randomCard = nil;

if ([self.cards count]) {
    unsigned index = arc4random() % [self.cards count];
    randomCard = self.cards[index];
    [self.cards removeObjectAtIndex:index];
}
return randomCard;
}

@end

1 个答案:

答案 0 :(得分:5)

.h文件中,您已将方法命名为addCard:,但在.m文件中,您拼写了方法addcard:

Objective-C区分大小写。

.m文件中更改此行:

-(void)addcard:(Card *)card

看起来像这样:

-(void)addCard:(Card *)card