---
title: "setData(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/nsmutabledata/setdata(_:)"
---

# setData(_:)

Replaces the entire contents of the receiver with the contents of another data object.

## Declaration

```swift
func setData(_ data: Data)
```

## Parameters

- `data`: The data object whose content replaces that of the receiver.

## Discussion

Discussion As part of its implementation, this method calls replaceBytes(in:withBytes:).

## See Also

### Modifying Bytes

- [replaceBytes(in:withBytes:)](foundation/nsmutabledata/replacebytes(in:withbytes:).md)
- [replaceBytes(in:withBytes:length:)](foundation/nsmutabledata/replacebytes(in:withbytes:length:).md)
- [resetBytes(in:)](foundation/nsmutabledata/resetbytes(in:).md)
