---
title: "fetchRequestFromTemplate(withName:substitutionVariables:)"
framework: coredata
role: symbol
role_heading: Instance Method
path: "coredata/nsmanagedobjectmodel/fetchrequestfromtemplate(withname:substitutionvariables:)"
---

# fetchRequestFromTemplate(withName:substitutionVariables:)

Returns a copy of the fetch request template with the variables substituted by values from the substitutions dictionary.

## Declaration

```swift
func fetchRequestFromTemplate(withName name: String, substitutionVariables variables: [String : Any]) -> NSFetchRequest<any NSFetchRequestResult>?
```

## Parameters

- `name`: A string containing the name of a fetch request template.
- `variables`: A dictionary containing key-value pairs where the keys are the names of variables specified in the template; the corresponding values are substituted before the fetch request is returned. The dictionary must provide values for all the variables in the template.

## Return Value

Return Value A copy of the fetch request template with the variables substituted by values from variables.

## Discussion

Discussion The variables dictionary must provide values for all the variables. If you want to test for a nil value, use [NSNull null]. This method provides the usual way to bind an “abstractly” defined fetch request template to a concrete fetch. For more details on using this method, see Creating Predicates.

## See Also

### Manipulating fetch request templates

- [fetchRequestTemplatesByName](coredata/nsmanagedobjectmodel/fetchrequesttemplatesbyname.md)
- [fetchRequestTemplate(forName:)](coredata/nsmanagedobjectmodel/fetchrequesttemplate(forname:).md)
- [setFetchRequestTemplate(_:forName:)](coredata/nsmanagedobjectmodel/setfetchrequesttemplate(_:forname:).md)
