Replaces the object at the index with the new object, possibly adding the object.
SDKs
- iOS 6.0+
- macOS 10.8+
- Mac Catalyst 13.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
Declaration
- (void)setObject:(Object Type)obj atIndexedSubscript:(NSUInteger)idx;
Parameters
anObject
The object with which to replace the object at index
index
in the array. This value must not benil
.Important
Raises an
NSInvalid
ifArgument Exception an
isObject nil
.index
The index of the object to be replaced. This value must not exceed the bounds of the array.
Important
Raises an
NSRange
ifException index
is beyond the end of the array.
Discussion
This method has the same behavior as the replace
method.
If index
is beyond the end of the array (that is, if index
is greater than or equal to the value returned by count
), an NSRange
is raised.
You shouldn’t need to call this method directly. Instead, this method is called when setting an object by index using subscripting.
mutableArray[3] = @"someValue"; // equivalent to [mutableArray replaceObjectAtIndex:3 withObject:@"someValue"]