---
title: "init(toMemory:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/outputstream/init(tomemory:)"
---

# init(toMemory:)

Returns an initialized output stream that will write to memory.

## Declaration

```swift
init(toMemory: ())
```

## Return Value

Return Value An initialized output stream that will write stream data to memory.

## Discussion

Discussion The stream must be opened before it can be used. The contents of the memory stream are retrieved by passing the constant NSStreamDataWrittenToMemoryStreamKey to property(forKey:).

## See Also

### Creating Streams

- [toMemory()](foundation/outputstream/tomemory().md)
- [init(toBuffer:capacity:)](foundation/outputstream/init(tobuffer:capacity:).md)
- [init(toFileAtPath:append:)](foundation/outputstream/init(tofileatpath:append:).md)
- [init(url:append:)](foundation/outputstream/init(url:append:)-5soau.md)
