What is the difference between:
的区别是什么:
[blah addObject:@"1"];
And
和
[blah insertObject:@"0" atIndex:0];
???
? ? ?
I know they're both for a NSMutableArray
.
我知道他们都是为了NSMutableArray。
1 个解决方案
#1
10
addObject
adds an object at last. insertObject:atIndex
adds an object at specified index. All objects further to that specified index are shifted one position right.
addObject最后添加一个对象。atIndex在指定的索引处添加一个对象。在指定索引后面的所有对象都被右移一个位置。
For example, say you have an array with following objects:
例如,假设您有一个具有以下对象的数组:
A B C D
And you add E using addObject
. Then it will look like:
用addObject添加E。然后它会看起来像:
A B C D E
Then you insert F at index 2. Then it will look like:
然后在索引2处插入F。然后它会看起来像:
A B F C D E
#1
10
addObject
adds an object at last. insertObject:atIndex
adds an object at specified index. All objects further to that specified index are shifted one position right.
addObject最后添加一个对象。atIndex在指定的索引处添加一个对象。在指定索引后面的所有对象都被右移一个位置。
For example, say you have an array with following objects:
例如,假设您有一个具有以下对象的数组:
A B C D
And you add E using addObject
. Then it will look like:
用addObject添加E。然后它会看起来像:
A B C D E
Then you insert F at index 2. Then it will look like:
然后在索引2处插入F。然后它会看起来像:
A B F C D E