CFWriteStream provides an interface for writing a byte stream either synchronously or asynchronously. You can create streams that write bytes to a block of memory, a file, or a generic socket. All streams need to be opened, using CFWriteStreamOpen(_:), before writing.

Use CFReadStream for reading byte streams, and for the functions, such as CFStreamCreatePairWithSocketToHost(_:_:_:_:_:), that create socket streams).

CFWriteStream is “toll-free bridged” with its Cocoa Foundation counterpart, OutputStream. This means that the Core Foundation type is interchangeable in function or method calls with the bridged Foundation object. Therefore, in a method where you see an NSOutputStream * parameter, you can pass in a CFWriteStreamRef, and in a function where you see a CFWriteStreamRef parameter, you can pass in an NSOutputStream instance. Note, however, that you may have either a delegate or callbacks but not both. See Toll-Free Bridged Types for more information on toll-free bridging.


Creating a Write Stream

func CFWriteStreamCreateWithAllocatedBuffers(CFAllocator!, CFAllocator!)

Creates a writable stream for a growable block of memory.

func CFWriteStreamCreateWithBuffer(CFAllocator!, UnsafeMutablePointer<UInt8>!, CFIndex)

Creates a writable stream for a fixed-size block of memory.

func CFWriteStreamCreateWithFile(CFAllocator!, CFURL!)

Creates a writable stream for a file.

Opening and Closing a Stream

func CFWriteStreamOpen(CFWriteStream!)

Opens a stream for writing.

Writing to a Stream

Examining Stream Properties

func CFWriteStreamCanAcceptBytes(CFWriteStream!)

Returns whether a writable stream can accept new data without blocking.

func CFWriteStreamCopyError(CFWriteStream!)

Returns the error associated with a stream.

func CFWriteStreamGetError(CFWriteStream!)

Returns the error status of a stream.

func CFWriteStreamGetStatus(CFWriteStream!)

Returns the current state of a stream.

Setting Stream Properties

Getting the CFWriteStream Type ID

func CFWriteStreamGetTypeID()

Returns the type identifier of all CFWriteStream objects.



Callback invoked when certain types of activity takes place on a writable stream.

Data Types


A reference to a writable stream object.