NSString

  • Function to return an array of NSRanges for substring in self. Searches the string from index 0, so ranges(of: ).first will be the first NSRange in the string. Note this is returning an NSRange, not a Swift Range. See http://stackoverflow.com/a/27041376/2580195 for why these two types of ranges are incompatible.

    If you only need the first range, and not as NSRange, use Swift’s range(of: ).

    Declaration

    Swift

    public func ranges(of searchString: String, options mask: NSString.CompareOptions = [NSString.CompareOptions.caseInsensitive]) -> [NSRange]

    Parameters

    searchString

    Substring to find.

    mask

    NSString.CompareOptions, defaults to NSString.CompareOptions.caseInsensitive.

    Return Value

    Array of NSRanges where searchString is in self.