Tor*_*ori 2 objective-c nsarray ios
我试图改组一个数组,但我得到一个"没有可见的@interface for'NSArray'在最后一个语句中声明选择器'exchangeObjectAtIndex:withObjectAtIndex:'.
如何宣布bArray?
NSArray *bArray;
Run Code Online (Sandbox Code Playgroud)
并在
- (void)viewDidLoad
[self shuffleb];
Run Code Online (Sandbox Code Playgroud)
然后
-(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];
}
Run Code Online (Sandbox Code Playgroud)
exchangeObjectAtIndex 是NSMutableArray的方法.
| 归档时间: |
|
| 查看次数: |
3780 次 |
| 最近记录: |