---
title: "variable(with:shape:dataType:name:)"
framework: metalperformanceshadersgraph
role: symbol
role_heading: Instance Method
path: "metalperformanceshadersgraph/mpsgraph/variable(with:shape:datatype:name:)"
---

# variable(with:shape:dataType:name:)

Creates a variable operation and returns the result tensor.

## Declaration

```swift
func variable(with data: Data, shape: [NSNumber], dataType: MPSDataType, name: String?) -> MPSGraphTensor
```

## Parameters

- `data`: The data for the tensor. The number of bytes should be sizeof(dataType)numberOfElements.
- `shape`: The shape of the output tensor. This has to be statically shaped.
- `dataType`: The dataType of the constant tensor.
- `name`: The name for the operation.

## Return Value

Return Value A valid MPSGraphTensor object.
