简体   繁体   中英

remove object at NSMutableArray in range

I am trying to remove objects at array starting at index 5 to the end of the list. I have a for loop to do this, however now I discovered

 - (void)removeObject:(id)anObject inRange:(NSRange)aRange

The question is what is the anObject here? I only need range as far as I know

removeObject:inRange: deletes an object within a certain range. This method would be useful if you wanted delete the string @"Hello World" only if it is one of the first 5 elements.

It sounds like what you are trying to do is delete all objects after the 5th element. If that is what you are trying to do, you should use the removeObjectsInRange: method. For example:

 NSRange r;
 r.location = 5;
 r.length = [someArray count]-5;

 [someArray removeObjectsInRange:r];

You want

- (void)removeObjectsInRange:(NSRange)aRange

Removes from the array each of the objects within a given range.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM