---
title: "groups(matching:)"
framework: contacts
role: symbol
role_heading: Instance Method
path: "contacts/cncontactstore/groups(matching:)"
---

# groups(matching:)

Fetches all groups matching the specified predicate.

## Declaration

```swift
func groups(matching predicate: NSPredicate?) throws -> [CNGroup]
```

## Parameters

- `predicate`: The predicate to use to fetch the matching groups. Set predicate to nil to match all groups.

## Return Value

Return Value An array of CNGroup objects that match the predicate. Discussion This method returns an empty array when no matching groups are found. If an error occurs, this method returns nil. You should use only the predicates defined in CNGroup class predicates. Compound predicates are not supported. Contacts may be members of one or more groups, depending upon the account they come from. note: In Swift, this method returns a nonoptional result and is marked with the throws keyword to indicate that it throws an error in cases of failure. You call this method in a try expression and handle any errors in the catch clauses of a do statement, as described in Error Handling in The Swift Programming Language and About Imported Cocoa Error Parameters.

## See Also

### Fetching groups and containers

- [defaultContainerIdentifier()](contacts/cncontactstore/defaultcontaineridentifier().md)
- [containers(matching:)](contacts/cncontactstore/containers(matching:).md)
