Contents

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