# `GSShape enumerateParentGroupsWithBlock:`

*Instance Method*

Invokes a block for each containing group, from the direct parent through the root group.

## Declaration

```swift
func enumerateParentGroups(_ code: @escaping (GSShapeGroup, UnsafeMutablePointer<ObjCBool>) -> Void)
```

```objc
- (void) enumerateParentGroupsWithBlock:(void (^)(GSShapeGroup *group, BOOL *stop)) code;
```

```python
enumerateParentGroupsWithBlock_(group: GSShapeGroup, stop: bool, code)
```

## Parameters

- `code` — The block to invoke for each containing group.

## Discussion

No groups are enumerated when [`GSShape.parentGroup`](/Core/GlyphsCore/GSShape/parentGroup) is `nil`. Set `stop` to `YES` to end the enumeration early.

## See Also

### Shape Hierarchy

- [`GSShape.parentGroupId`](/Core/GlyphsCore/GSShape/parentGroupId) — The ID of the parent group.
- [`GSShape.parentGroup`](/Core/GlyphsCore/GSShape/parentGroup) — The direct containing group in the layer’s shape hierarchy.

