<!--
{
  "availability" : [
    "iOS: 2.0.0 - 11.0.0",
    "iPadOS: 2.0.0 - 11.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.0.0 - 10.13.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSArchiver/init(forWritingWith:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSArchiver(im)initForWritingWithMutableData:"
  },
  "title" : "init(forWritingWith:)"
}
-->

# init(forWritingWith:)

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

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

## Parameters

`mdata`

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

## Return Value

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

## Discussion

Raises an `NSInvalidArgumentException` if `data` is `nil`.

## See Also

[`archiverData`](/documentation/Foundation/NSArchiver/archiverData)

The receiver’s archive data.

  [Archives and Serializations Programming Guide](https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Archiving/Archiving.html#//apple_ref/doc/uid/10000047i)



---

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)