Objective C 및 Cocoa로 그립을 잡으려고하고 있으므로 여기에서 잘못된 용어를 사용하고있을 수 있습니다.Array 객체에서 objectAtIndex를 사용하는 방법
내 주요 AppDelegate.h 두 가지 방법, deckOfCards & pickACard을 가지고 & AppDelegate.m, 읽 한 벌의 카드에 대한 목표 C 클래스를했습니다. deckOfCards 그냥있는 NSMutableArray는 다음 pickACard에서이 같은 새로운 배열을 만들 문자열 형태로 기록 된 모든 카드 유형입니다 :
-(void)pickACard
{
DeckOfCards *newDeck = [[DeckOfCards alloc] init];
int r = arc4random() % 52;
NSLog (@"The card you picked is: %@, and there are %i cards left", [newDeck objectAtIndex:r], [newDeck count]);
[newDeck removeObjectAtIndex:r];
}
그러나 엑스 코드 나는이 새로운 배열에 objectAtIndex & removeObjectAtIndex을 사용할 수 없다는 것을 말하고있다 때문에, 나는 무작위로 카드를 선택한 다음 배열의 해당 부분을 제거하여 "팩에서 제거"할 수 없습니다.
이것은 모두 deckOfCards에있을 때 작동했지만 AppDelegate.m에 의해 호출되었을 때 새로운 배열을 작성하므로 다른 카드를 가져올 수 있지만 팩에서 둘 이상을 제거하지 마십시오.
나는이 새로운 배열을 제대로 만들지 않을 것이라고 추측 할 것입니다. 있는 NSMutableArray의 서브 클래스
@implementation DeckOfCards
-(void)deckOfCards
{
NSMutableArray *deckOfCards = [NSMutableArray arrayWithObjects:
@"One of Hearts", @"Two of Hearts"..., nil];
}
-(void)pickACard
{
DeckOfCards *newDeck = [[DeckOfCards alloc] init];
int r = arc4random() % 52;
NSLog (@"The card you picked is: %@, and there are %i cards left",[newDeck objectAtIndex:r], [newDeck count]);
[newDeck removeObjectAtIndex:r];
}
@end
'DeckOfCards *'란 무엇입니까? – kennytm
은 NSArray 하위 클래스 인 DeckOfCards입니까? 또는 그것의 구현에 NSArray를 사용합니까? – wattson12
실제 오류 메시지는 무엇입니까? – rdelmar