---
title: "addFileWrapper(_:)"
framework: foundation
role: symbol
role_heading: Instance Method
path: "foundation/filewrapper/addfilewrapper(_:)"
---

# addFileWrapper(_:)

Adds a child file wrapper to the receiver, which must be a directory file wrapper.

## Declaration

```swift
func addFileWrapper(_ child: FileWrapper) -> String
```

## Parameters

- `child`: File wrapper to add to the directory.

## Return Value

Return Value Dictionary key used to store fileWrapper in the directory’s list of file wrappers. The dictionary key is a unique filename, which is the same as the passed-in file wrapper’s preferred filename unless that name is already in use as a key in the directory’s dictionary of children. See Accessing File Wrapper Identities in File System Programming Guide for more information about the file-wrapper list structure.

## Discussion

Discussion Use this method to add an existing file wrapper as a child of a directory file wrapper. If the file wrapper does not have a preferred filename, set the preferredFilename property to give it one before calling addFileWrapper(_:). To create a new file wrapper and add it to a directory, use the addRegularFile(withContents:preferredFilename:) method. Special Considerations This method raises NSInternalInconsistencyException if the receiver is not a directory file wrapper. This method raises NSInvalidArgumentException if the child file wrapper doesn’t have a preferred name.

## See Also

### Related Documentation

- [preferredFilename](foundation/filewrapper/preferredfilename.md)

### Accessing File-Wrapper Information

- [fileWrappers](foundation/filewrapper/filewrappers.md)
- [removeFileWrapper(_:)](foundation/filewrapper/removefilewrapper(_:).md)
- [addFile(withPath:)](foundation/filewrapper/addfile(withpath:).md)
- [addRegularFile(withContents:preferredFilename:)](foundation/filewrapper/addregularfile(withcontents:preferredfilename:).md)
- [addSymbolicLink(withDestination:preferredFilename:)](foundation/filewrapper/addsymboliclink(withdestination:preferredfilename:).md)
- [keyForChildFileWrapper(_:)](foundation/filewrapper/keyforchildfilewrapper(_:).md)
- [symbolicLinkDestination()](foundation/filewrapper/symboliclinkdestination().md)
- [symbolicLinkDestinationURL](foundation/filewrapper/symboliclinkdestinationurl.md)
