---
title: "beginSheet(forDirectory:file:modalFor:modalDelegate:didEnd:contextInfo:)"
framework: securityinterface
role: symbol
role_heading: Instance Method
path: "securityinterface/sfkeychainsavepanel/beginsheet(fordirectory:file:modalfor:modaldelegate:didend:contextinfo:)"
---

# beginSheet(forDirectory:file:modalFor:modalDelegate:didEnd:contextInfo:)

Displays a sheet that allows a user to create a new keychain.

## Declaration

```swift
func beginSheet(forDirectory path: String!, file name: String!, modalFor docWindow: NSWindow!, modalDelegate delegate: Any!, didEnd didEndSelector: Selector!, contextInfo: UnsafeMutableRawPointer!)
```

## Parameters

- `path`: The path to the folder where the keychain is created. Specify nil for ~/Library/Keychains.
- `name`: The keychain name to be automatically displayed in the Save As field of the sheet.
- `docWindow`: The parent window to which the sheet is attached. If this parameter is nil, the behavior defaults to a standalone modal window.
- `delegate`: The delegate object in which the method specified in the didEndSelector parameter is implemented.
- `didEndSelector`: A method selector for a delegate method called after the modal session has ended, but before the sheet has been dismissed. Implementation of this delegate method is optional.
- `contextInfo`: A pointer to data that is passed to the delegate method. You can use this data pointer for any purpose you wish.

## Discussion

Discussion The delegate method has the following signature: - (void)createPanelDidEnd:(NSWindow *)sheet         returnCode:(int)returnCode         contextInfo:(void *)contextInfo The parameters for the delegate method are: The delegate method may dismiss the keychain settings sheet itself; if it does not, the sheet is dismissed on return from the beginSheetForDirectory:... method. Use the keychain() method to obtain the keychain created by the user.

## See Also

### Related Documentation

- [keychain()](securityinterface/sfkeychainsavepanel/keychain().md)
- [runModal(forDirectory:file:)](securityinterface/sfkeychainsavepanel/runmodal(fordirectory:file:).md)

### Displaying a Sheet or Panel

- [setPassword(_:)](securityinterface/sfkeychainsavepanel/setpassword(_:).md)
- [runModal(forDirectory:file:)](securityinterface/sfkeychainsavepanel/runmodal(fordirectory:file:).md)
