Sunday, 8 September 2013

No visible @interface for 'NSArray' declares the selector 'exchangeObjectAtIndex:withObjectAtIndex

No visible @interface for 'NSArray' declares the selector
'exchangeObjectAtIndex:withObjectAtIndex

I am trying to shuffle an array, but I get a "No visible @interface for
'NSArray' declares the selector 'exchangeObjectAtIndex:withObjectAtIndex:'
on the last statement.
How should bArray be declared?
NSArray *bArray;
and in
- (void)viewDidLoad
[self shuffleb];
then
-(void) shufflb
{
bArray = [NSArray arrayWithObjects:
@"ca",
@"do",
@"ba",
@"tr",
@"bu",
@"bl",
@"bo",
@"pu",
nil];
NSInteger count = [bArray count];
for (NSUInteger i = 0; i < count; ++i) {
// Select a random element between i and end of array to swap with.
NSInteger nElements = count - i;
n = (arc4random() % nElements) + i;
[bArray exchangeObjectAtIndex:i withObjectAtIndex:n];
}

No comments:

Post a Comment