---
title: toMemory()
framework: foundation
role: symbol
role_heading: Type Method
path: foundation/outputstream/tomemory()
---

# toMemory()

Creates and returns an initialized output stream that will write stream data to memory.

## Declaration

```swift
class func toMemory() -> Self
```

## 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. You retrieve the contents of the memory stream by sending the message property(forKey:) to the receiver with an argument of NSStreamDataWrittenToMemoryStreamKey.

## See Also

### Related Documentation

- [Stream Programming Guide](apple-archive/documentation/Cocoa/Conceptual/Streams.md)

### Creating Streams

- [init(toMemory:)](foundation/outputstream/init(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)
