Instance Method

number(from:)

Returns an NSNumber object created by parsing a given string.

Declaration

func number(from string: String) -> NSNumber?

Parameters

string

An NSString object that is parsed to generate the returned number object.

Return Value

An NSNumber object created by parsing string using the receiver’s format, or nil if no single number could be parsed.

Discussion

If a string contains any characters other than numerical digits or locale-appropriate group or decimal separators, parsing will fail.

Any leading or trailing space separator characters in a string are ignored. For example, the strings “ 5”, “5 ”, and “5” all produce the number 5.

See Also

Converting Between Numbers and Strings

func getObjectValue(AutoreleasingUnsafeMutablePointer<AnyObject?>?, for: String, range: UnsafeMutablePointer<NSRange>?)

Returns by reference a cell-content object after creating it from a range of characters in a given string.

func string(from: NSNumber) -> String?

Returns a string containing the formatted value of the provided number object.

class func localizedString(from: NSNumber, number: NumberFormatter.Style) -> String

Returns a localized number string with the specified style.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software