Instance Method

getCString(_:)

Invokes getCString(_:maxLength:range:remaining:) with NSMaximumStringLength as the maximum length, the receiver’s entire extent as the range, and NULL for the remaining range.

Declaration

func getCString(_ bytes: UnsafeMutablePointer<Int8>)

Discussion

buffer must be large enough to contain the resulting C-string plus a terminating NULL character (which this method adds—[string cStringLength]).

Raises an NSCharacterConversionException if the receiver can’t be represented in the default C-string encoding without loss of information. Use canBeConverted(to:) if necessary to check whether a string can be losslessly converted to the default C-string encoding. If it can’t, use lossyCString() or data(using:allowLossyConversion:) to get a C-string representation with some loss of information.

See Also

Deprecated

class func string(withCString: UnsafePointer<Int8>) -> Any?

Creates a new string using a given C-string.

Deprecated
init?(cString: UnsafePointer<Int8>)

Initializes the receiver, a newly allocated NSString object, by converting the data in a given C-string from the default C-string encoding into the Unicode character encoding.

Deprecated
class func string(withCString: UnsafePointer<Int8>, length: Int) -> Any?

Returns a string containing the characters in a given C-string.

Deprecated
init?(cString: UnsafePointer<Int8>, length: Int)

Initializes the receiver, a newly allocated NSString object, by converting the data in a given C-string from the default C-string encoding into the Unicode character encoding.

Deprecated
init?(cStringNoCopy: UnsafeMutablePointer<Int8>, length: Int, freeWhenDone: Bool)

Initializes the receiver, a newly allocated NSString object, by converting the data in a given C-string from the default C-string encoding into the Unicode character encoding.

Deprecated
class func string(withContentsOfFile: String) -> Any?

Returns a string created by reading data from the file named by a given path.

Deprecated
init?(contentsOfFile: String)

Initializes the receiver, a newly allocated NSString object, by reading data from the file named by path.

Deprecated
class func string(withContentsOf: URL) -> Any?

Returns a string created by reading data from the file named by a given URL.

Deprecated
init?(contentsOf: URL)

Initializes the receiver, a newly allocated NSString object, by reading data from the location named by a given URL.

Deprecated
func write(toFile: String, atomically: Bool) -> Bool

Writes the contents of the receiver to the file specified by a given path.

Deprecated
func write(to: URL, atomically: Bool) -> Bool

Writes the contents of the receiver to the location specified by a given URL.

Deprecated
func getCharacters(UnsafeMutablePointer<unichar>)

Copies all characters from the receiver into a given buffer.

Deprecated
func cString() -> UnsafePointer<Int8>?

Returns a representation of the receiver as a C string in the default C-string encoding.

Deprecated
func lossyCString() -> UnsafePointer<Int8>?

Returns a representation of the receiver as a C string in the default C-string encoding, possibly losing information in converting to that encoding.

Deprecated
func cStringLength() -> Int

Returns the length in char-sized units of the receiver’s C-string representation in the default C-string encoding.

Deprecated
func getCString(UnsafeMutablePointer<Int8>, maxLength: Int)

Invokes getCString(_:maxLength:range:remaining:) with maxLength as the maximum length in char-sized units, the receiver’s entire extent as the range, and NULL for the remaining range.

Deprecated
func getCString(UnsafeMutablePointer<Int8>, maxLength: Int, range: NSRange, remaining: NSRangePointer?)

Converts the receiver’s content to the default C-string encoding and stores them in a given buffer.

Deprecated
func addingPercentEscapes(using: UInt) -> String?

Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string.

Deprecated
func replacingPercentEscapes(using: UInt) -> String?

Returns a new string made by replacing in the receiver all percent escapes with the matching characters as determined by a given encoding.

Deprecated
func draw(with: NSRect, options: NSString.DrawingOptions, attributes: [NSAttributedString.Key : Any]?)

Draws the receiver with the specified options and other display characteristics of the given attributes, within the specified rectangle in the current graphics context.

Deprecated
func boundingRect(with: NSSize, options: NSString.DrawingOptions, attributes: [NSAttributedString.Key : Any]?) -> NSRect

Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics, within the specified rectangle in the current graphics context.

Deprecated

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