<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreFoundation",
  "identifier" : "/documentation/CoreFoundation/CFWriteStream",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Core Foundation"
    ],
    "preciseIdentifier" : "c:@T@CFWriteStreamRef"
  },
  "title" : "CFWriteStream"
}
-->

# CFWriteStream

```
class CFWriteStream
```

## Overview

`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(_:)`](/documentation/CoreFoundation/CFWriteStreamOpen(_:)), before writing.

Use [`CFReadStream`](/documentation/CoreFoundation/CFReadStream) for reading byte streams, and for the functions, such as [`CFStreamCreatePairWithSocketToHost(_:_:_:_:_:)`](/documentation/CoreFoundation/CFStreamCreatePairWithSocketToHost(_:_:_:_:_:)), that create socket streams).

`CFWriteStream` is “toll-free bridged” with its Cocoa Foundation counterpart, <doc://com.apple.documentation/documentation/Foundation/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](https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFDesignConcepts/Articles/tollFreeBridgedTypes.html#//apple_ref/doc/uid/TP40010677) for more information on toll-free bridging.

## Topics

### Creating a Write Stream

[`CFWriteStreamCreateWithAllocatedBuffers(_:_:)`](/documentation/CoreFoundation/CFWriteStreamCreateWithAllocatedBuffers(_:_:))

Creates a writable stream for a growable block of memory.

[`CFWriteStreamCreateWithBuffer(_:_:_:)`](/documentation/CoreFoundation/CFWriteStreamCreateWithBuffer(_:_:_:))

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

[`CFWriteStreamCreateWithFile(_:_:)`](/documentation/CoreFoundation/CFWriteStreamCreateWithFile(_:_:))

Creates a writable stream for a file.

### Opening and Closing a Stream

[`CFWriteStreamClose(_:)`](/documentation/CoreFoundation/CFWriteStreamClose(_:))

Closes a writable stream.

[`CFWriteStreamOpen(_:)`](/documentation/CoreFoundation/CFWriteStreamOpen(_:))

Opens a stream for writing.

### Writing to a Stream

[`CFWriteStreamWrite(_:_:_:)`](/documentation/CoreFoundation/CFWriteStreamWrite(_:_:_:))

Writes data to a writable stream.

### Scheduling a Write Stream

[`CFWriteStreamScheduleWithRunLoop(_:_:_:)`](/documentation/CoreFoundation/CFWriteStreamScheduleWithRunLoop(_:_:_:))

Schedules a stream into a run loop.

[`CFWriteStreamUnscheduleFromRunLoop(_:_:_:)`](/documentation/CoreFoundation/CFWriteStreamUnscheduleFromRunLoop(_:_:_:))

Removes a stream from a particular run loop.

### Examining Stream Properties

[`CFWriteStreamCanAcceptBytes(_:)`](/documentation/CoreFoundation/CFWriteStreamCanAcceptBytes(_:))

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

[`CFWriteStreamCopyProperty(_:_:)`](/documentation/CoreFoundation/CFWriteStreamCopyProperty(_:_:))

Returns the value of a property for a stream.

[`CFWriteStreamCopyError(_:)`](/documentation/CoreFoundation/CFWriteStreamCopyError(_:))

Returns the error associated with a stream.

[`CFWriteStreamGetError(_:)`](/documentation/CoreFoundation/CFWriteStreamGetError(_:))

Returns the error status of a stream.

[`CFWriteStreamGetStatus(_:)`](/documentation/CoreFoundation/CFWriteStreamGetStatus(_:))

Returns the current state of a stream.

### Setting Stream Properties

[`CFWriteStreamSetClient(_:_:_:_:)`](/documentation/CoreFoundation/CFWriteStreamSetClient(_:_:_:_:))

Assigns a client to a stream, which receives callbacks when certain events occur.

[`CFWriteStreamSetProperty(_:_:_:)`](/documentation/CoreFoundation/CFWriteStreamSetProperty(_:_:_:))

Sets the value of a property for a stream.

### Getting the CFWriteStream Type ID

[`CFWriteStreamGetTypeID()`](/documentation/CoreFoundation/CFWriteStreamGetTypeID())

Returns the type identifier of all CFWriteStream objects.

### Callbacks

[`CFWriteStreamClientCallBack`](/documentation/CoreFoundation/CFWriteStreamClientCallBack)

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



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)