There is no built-in method for this, but it's pretty easy to iterate over the characters of the string and build a new string without duplicates:
NSString *input = @"addbcddaa";
NSMutableSet *seenCharacters = [NSMutableSet set];
NSMutableString *result = [NSMutableString string];
[input enumerateSubstringsInRange:NSMakeRange(0, input.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
if (![seenCharacters containsObject:substring]) {
[seenCharacters addObject:substring];
[result appendString:substring];
}
}];
NSLog(@"String with duplicate characters removed: %@", result);
NSLog(@"Sorted characters in input: %@", [seenCharacters.allObjects sortedArrayUsingSelector:@selector(compare:)]);
This results in the string "adbc"
(duplicates removed) and the sorted array of unique characters ["a", "b", "c", "d"]
.