<!--
{
  "availability" : [
    "iOS: 2.0.0 - 12.0.0",
    "iPadOS: 2.0.0 - 12.0.0",
    "macCatalyst: 13.1.0 - 13.1.0",
    "macOS: 10.2.0 - 10.14.0",
    "tvOS: 9.0.0 - 12.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 5.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSKeyedArchiver/init(forWritingWith:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSKeyedArchiver(im)initForWritingWithMutableData:"
  },
  "title" : "init(forWritingWith:)"
}
-->

# init(forWritingWith:)

Initializes an archiver to encode data into a given a mutable-data object.

```
init(forWritingWith data: NSMutableData)
```

## Parameters

`data`

The mutable-data object into which the archive is written.

## Discussion

When you finish encoding data, you must invoke [`finishEncoding()`](/documentation/Foundation/NSKeyedArchiver/finishEncoding()) at which point `data` is filled. The format of the receiver is `NSPropertyListBinaryFormat_v1_0`.

## See Also

  [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)