Mac Developer Library

Developer

Foundation Framework Reference NSMutableCharacterSet Class Reference

Options
Deployment Target:

On This Page
Language:

NSMutableCharacterSet

The NSMutableCharacterSet class declares the programmatic interface to objects that manage a modifiable set of Unicode characters. You can add or remove characters from a mutable character set as numeric values in NSRange structures or as character values in strings, combine character sets by union or intersection, and invert a character set. More...

Inheritance


Import Statement


import Foundation @import Foundation;

Availability


Available in OS X v10.0 and later.
  • Adds to the receiver the characters whose Unicode values are in a given range.

    Declaration

    Swift

    func addCharactersInRange(_ aRange: NSRange)

    Objective-C

    - (void)addCharactersInRange:(NSRange)aRange

    Parameters

    aRange

    The range of characters to add.

    aRange.location is the value of the first character to add; aRange.location + aRange.length– 1 is the value of the last. If aRange.length is 0, this method has no effect.

    Discussion

    This code excerpt adds to a character set the lowercase English alphabetic characters:

    • NSMutableCharacterSet *aCharacterSet = [[NSMutableCharacterSet alloc] init];
    • NSRange lcEnglishRange;
    • lcEnglishRange.location = (unsigned int)'a';
    • lcEnglishRange.length = 26;
    • [aCharacterSet addCharactersInRange:lcEnglishRange];

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Removes from the receiver the characters whose Unicode values are in a given range.

    Declaration

    Swift

    func removeCharactersInRange(_ aRange: NSRange)

    Objective-C

    - (void)removeCharactersInRange:(NSRange)aRange

    Parameters

    aRange

    The range of characters to remove.

    aRange.location is the value of the first character to remove; aRange.location + aRange.length– 1 is the value of the last. If aRange.length is 0, this method has no effect.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Adds to the receiver the characters in a given string.

    Declaration

    Swift

    func addCharactersInString(_ aString: String)

    Objective-C

    - (void)addCharactersInString:(NSString *)aString

    Parameters

    aString

    The characters to add to the receiver.

    Discussion

    This method has no effect if aString is empty.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Removes from the receiver the characters in a given string.

    Declaration

    Swift

    func removeCharactersInString(_ aString: String)

    Objective-C

    - (void)removeCharactersInString:(NSString *)aString

    Parameters

    aString

    The characters to remove from the receiver.

    Discussion

    This method has no effect if aString is empty.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

  • Replaces all the characters in the receiver with all the characters it didn’t previously contain.

    Declaration

    Swift

    func invert()

    Objective-C

    - (void)invert

    Discussion

    Inverting a mutable character set, whether by invert or by invertedSet, is much less efficient than inverting an immutable character set with invertedSet.

    Import Statement

    import Foundation

    Availability

    Available in OS X v10.0 and later.

    See Also

    – invertedSet (NSCharacterSet)