# `MDPSplitView toggleSubview:dividerIndex:lastWidth:animationDuration:collapsesRightward:widthConstraint:completionHandler:`

*Instance Method*

Helper method to toggle a (vertically split) split view’s subview.

## Declaration

```swift
func toggleSubview(_ subview: NSView, dividerIndex: UInt, lastWidth: UnsafeMutablePointer<CGFloat>, animationDuration: TimeInterval, collapsesRightward: Bool, widthConstraint: NSLayoutConstraint, completionHandler: ((Bool) -> Void)? = nil)
```

```swift
func toggleSubview(_ subview: NSView, dividerIndex: UInt, lastWidth: UnsafeMutablePointer<CGFloat>, animationDuration: TimeInterval, collapsesRightward: Bool, widthConstraint: NSLayoutConstraint) async -> Bool
```

```objc
- (void) toggleSubview:(NSView *) subview dividerIndex:(NSUInteger) dividerIndex lastWidth:(CGFloat *) lastWidth animationDuration:(NSTimeInterval) animationDuration collapsesRightward:(BOOL) collapsesRightward widthConstraint:(NSLayoutConstraint *) widthConstraint completionHandler:(void (^)(BOOL isOpen)) completionHandler;
```

```python
toggleSubview_dividerIndex_lastWidth_animationDuration_collapsesRightward_widthConstraint_completionHandler_(subview: NSView, dividerIndex: int, lastWidth: float, animationDuration: float, collapsesRightward: bool, widthConstraint: NSLayoutConstraint, isOpen: bool, completionHandler)
```

## Parameters

- `subview` — The subview to toggle.
- `dividerIndex` — The index of the divider to position.
- `lastWidth` — A reference to the variable you store the last width of the subview in.
- `animationDuration` — The duration of the animation.
- `collapsesRightward` — Whether you want to have the subview collapse rightward (or leftward, if NO).
- `widthConstraint` — The width constraint you have applied to the subview so that it doesn’t become too narrow.
- `completionHandler` — The completion handler that is called, once the animation has ended.

## Discussion

This is a helper method to toggle a split view’s subview. It is animated by calling `-setPosition:ofDividerAtIndex:`. There are two versions: one for split views with vertical dividers (this one) and another for those with horizontal dividers.

