---
title: "init(forWritingWith:)"
framework: foundation
role: symbol
role_heading: Initializer
path: "foundation/nsarchiver/init(forwritingwith:)"
---

# init(forWritingWith:)

Returns an archiver, initialized to encode stream and version information into a given mutable data object.

## Declaration

```swift
init(forWritingWith mdata: NSMutableData)
```

## Parameters

- `mdata`: The mutable data object into which to write the archive. This value must not be nil.

## Return Value

Return Value An archiver object, initialized to encode stream and version information into data.

## Discussion

Discussion Raises an NSInvalidArgumentException if data is nil.

## See Also

### Related Documentation

- [archiverData](foundation/nsarchiver/archiverdata.md)
- [Archives and Serializations Programming Guide](apple-archive/documentation/Cocoa/Conceptual/Archiving.md)
