---
title: "setFetchRequestTemplate(_:forName:)"
framework: coredata
role: symbol
role_heading: Instance Method
path: "coredata/nsmanagedobjectmodel/setfetchrequesttemplate(_:forname:)"
---

# setFetchRequestTemplate(_:forName:)

Associates the specified fetch request with the receiver using the given name.

## Declaration

```swift
func setFetchRequestTemplate(_ fetchRequestTemplate: NSFetchRequest<any NSFetchRequestResult>?, forName name: String)
```

## Parameters

- `fetchRequestTemplate`: A fetch request, typically containing predicates with variables for substitution.
- `name`: A string that specifies the name of the fetch request template.

## Discussion

Discussion For more details on using this method, see Creating Predicates. Special Considerations This method raises an exception if the receiver has been used by an object graph manager.

## See Also

### Manipulating fetch request templates

- [fetchRequestTemplatesByName](coredata/nsmanagedobjectmodel/fetchrequesttemplatesbyname.md)
- [fetchRequestTemplate(forName:)](coredata/nsmanagedobjectmodel/fetchrequesttemplate(forname:).md)
- [fetchRequestFromTemplate(withName:substitutionVariables:)](coredata/nsmanagedobjectmodel/fetchrequestfromtemplate(withname:substitutionvariables:).md)
