Ben*_*Ben 2 objective-c nsmutablearray
我试图删除索引1处的对象,但代码将无法编译.
我也不明白这一点:我将"iphone"字符串设置为索引0,然后将其从索引0中删除,但输出仍然首先显示"iphone".任何人都可以向我解释一下吗?
int main (int argc, const char * argv[])
{
@autoreleasepool {
//create three string objetc
NSString *banana = @"This is banana";
NSString *apple = @"This is apple";
NSString *iphone =@"This is iPhone";
//create an empty array
NSMutableArray *itemList = [NSMutableArray array];
// add the item to the array
[itemList addObject:banana];
[itemList addObject:apple];
// put the iphone to the at first
[itemList insertObject:iphone atIndex:0];
for (NSString *l in itemList) {
NSLog(@"The Item in the list is %@",l);
}
[itemList removeObject:0];
[itemList removeObject:1];// this is not allow it
NSLog(@"now the first item in the list is %@",[itemList objectAtIndex:0]);
NSLog(@"now the second time in the list is %@",[itemList objectAtIndex:1]);
NSLog(@"now the thrid item in the list is %@",[itemList objectAtIndex:2]);
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
edc*_*591 10
那应该是
[itemList removeObjectAtIndex:0];
[itemList removeObjectAtIndex:1];
Run Code Online (Sandbox Code Playgroud)
该方法在文档中明确说明NSMutableArray.在提出问题之前,请务必查阅正确的文档.
| 归档时间: |
|
| 查看次数: |
8490 次 |
| 最近记录: |