Returns the character at a given UTF-16 code unit index.
Language
- Swift
- Objective-C
SDKs
- iOS 2.0+
- macOS 10.0+
- tvOS 9.0+
- watchOS 2.0+
Framework
- Foundation
On This Page
Declaration
- (unichar)characterAtIndex:(NSUInteger)index;
Parameters
index
-
The index of the character to retrieve.
Important
Raises an
NSRangeException
ifindex
lies beyond the end of the receiver.
Return Value
The character at the array position given by index
.
Discussion
You should always use the rangeOfComposedCharacterSequenceAtIndex:
or rangeOfComposedCharacterSequencesForRange:
method to determine character boundaries, so that any surrogate pairs or character clusters are handled correctly.