Class

Scanner

The NSScanner class is an abstract superclass of a class cluster that declares the programmatic interface for an object that scans values from an NSString object.

Overview

An NSScanner object interprets and converts the characters of an NSString object into number and string values. You assign the scanner’s string on creating it, and the scanner progresses through the characters of that string from beginning to end as you request items.

Because of the nature of class clusters, scanner objects aren’t actual instances of the NSScanner class but one of its private subclasses. Although a scanner object’s class is private, its interface is public, as declared by this abstract superclass, NSScanner. The primitive methods of NSScanner are Scanner and all of the methods listed under Configuring a Scanner. The objects you create using this class are referred to as scanner objects (and when no confusion will result, merely as scanners).

You can set an NSScanner object to ignore a set of characters as it scans the string using the charactersToBeSkipped property. Characters in the skip set are skipped over before scanning the target. The default set of characters to skip is the whitespace and newline character set.

To retrieve the unscanned remainder of the string, use [[scanner string] substring(from:)[scanner scanLocation]].

Symbols

Creating a Scanner

class func localizedScanner(with: String)

Returns an NSScanner object that scans a given string according to the user’s default locale.

init(string: String)

Returns an NSScanner object initialized to scan a given string.

Getting a Scanner’s String

var string: String

The string the scanner will scan.

Configuring a Scanner

var scanLocation: Int

The character position at which the receiver will begin its next scanning operation.

var caseSensitive: Bool

Flag that indicates whether the receiver distinguishes case in the characters it scans.

var charactersToBeSkipped: CharacterSet?

Character set containing the characters the scanner ignores when looking for a scannable element.

var locale: Any?

The locale to use when scanning.

Scanning a String

func scanCharacters(from: CharacterSet, into: AutoreleasingUnsafeMutablePointer<NSString?>?)

Scans the string as long as characters from a given character set are encountered, accumulating characters into a string that’s returned by reference.

func scanUpToCharacters(from: CharacterSet, into: AutoreleasingUnsafeMutablePointer<NSString?>?)

Scans the string until a character from a given character set is encountered, accumulating characters into a string that’s returned by reference.

func scanDecimal(UnsafeMutablePointer<Decimal>?)

Scans for an NSDecimal value, returning a found value by reference.

func scanDouble(UnsafeMutablePointer<Double>?)

Scans for a double value, returning a found value by reference.

func scanFloat(UnsafeMutablePointer<Float>?)

Scans for a float value, returning a found value by reference.

func scanHexDouble(UnsafeMutablePointer<Double>?)

Scans for a double value from a hexadecimal representation, returning a found value by reference.

func scanHexFloat(UnsafeMutablePointer<Float>?)

Scans for a double value from a hexadecimal representation, returning a found value by reference.

func scanHexInt32(UnsafeMutablePointer<UInt32>?)

Scans for an unsigned value from a hexadecimal representation, returning a found value by reference.

func scanHexInt64(UnsafeMutablePointer<UInt64>?)

Scans for a long long value from a hexadecimal representation, returning a found value by reference.

func scanInt(UnsafeMutablePointer<Int>?)

Scans for an NSInteger value from a decimal representation, returning a found value by reference

func scanInt32(UnsafeMutablePointer<Int32>?)

Scans for an int value from a decimal representation, returning a found value by reference.

func scanInt64(UnsafeMutablePointer<Int64>?)

Scans for a long long value from a decimal representation, returning a found value by reference.

func scanString(String, into: AutoreleasingUnsafeMutablePointer<NSString?>?)

Scans a given string, returning an equivalent string object by reference if a match is found.

func scanUnsignedLongLong(UnsafeMutablePointer<UInt64>?)

Scans for an unsigned long long value from a decimal representation, returning a found value by reference.

func scanUpTo(String, into: AutoreleasingUnsafeMutablePointer<NSString?>?)

Scans the string until a given string is encountered, accumulating characters into a string that’s returned by reference.

var isAtEnd: Bool

Flag that indicates whether the receiver has exhausted all significant characters.

Relationships

Inherits From