---
title: "SKIndexAddDocument(_:_:_:_:)"
framework: Core Services
role: symbol
role_heading: Function
platforms: [macOS 10.3+]
path: coreservices/1444897-skindexadddocument
---

# SKIndexAddDocument(_:_:_:_:)

Adds location information for a file-based document, and the document’s textual content, to an index.

## Declaration

```swift
func SKIndexAddDocument(_ inIndex: SKIndex!, _ inDocument: SKDocument!, _ inMIMETypeHint: CFString!, _ inCanReplace: Bool) -> Bool
```

## Parameters

- `inIndex`: The index to which you are adding the document URL object (doc://com.apple.documentation/documentation/coreservices/skdocument).
- `inDocument`: The document URL object (of type doc://com.apple.documentation/documentation/coreservices/skdocument) , containing a file-based document’s location information, to add to the index. You can release the document URL object immediately after adding it to the index.
- `inMIMETypeHint`: The MIME type hint for the specified file-based document. Can be NULL. In Search Kit, common MIME type hints include text/plain, text/rtf, text/html, text/pdf, and application/msword. Specify a MIME type hint to help Spotlight determine which of its metadata importers to use when Search Kit is indexing a file-based document. Search Kit uses filename extensions and type/creator codes in attempting to determine file types when indexing files. See doc://com.apple.documentation/documentation/coreservices/1447859-skloaddefaultextractorplugins. You can circumvent Search Kit’s file type determination process, or override it, by using a MIME type hint.
- `inCanReplace`: A Boolean value specifying whether Search Kit will overwrite a document’s index entry (true, indicated by 1 or kCFBooleanTrue), or retain the entry if it exists (false, indicated by 0 or kCFBoolenFalse).

## Return Value

Return Value A Boolean value of true on success, or false on failure. Also returns false if the document has an entry in the index and inCanReplace is set to false.

## Discussion

Discussion  The document scheme must be of type “file” to use this function. If it’s not, call SKIndexAddDocumentWithText(_:_:_:_:) instead. For more information on schemes, see http://www.iana.org/assignments/uri-schemes.html. This function uses the referenced document and the optional MIME type hint to get the document’s textual content using the Spotlight metadata importers. If you do not supply a MIME type hint, Spotlight’s importers will use filename extensions and type/creator codes to guess file types. Search Kit indexes any nonexecutable file associated with a document URL object (of type SKDocument) that you hand to this function, even nontext files such as images. Your application takes responsibility for ensuring that the document URL objects you pass to SKIndexAddDocument are in fact the locations of files you want to index. If your application did not call SKLoadDefaultExtractorPlugIns(), Search Kit indexes the first 10 MB of a document. Otherwise, Search Kit indexes the entire document up to the index file size limit of 4 GB. Search Kit is thread-safe. You can use separate indexing and searching threads. Your application is responsible for ensuring that no more than one process is open at a time for writing to an index. A single Search Kit index can hold up to 4 billion document URL objects and their associated textual content. Special Considerations In the current implementation of Search Kit, some functions do not provide expected results unless you follow SKIndexAddDocument with a call to SKIndexFlush(_:). The affected functions include SKIndexGetDocumentCount(_:), SKIndexGetDocumentTermCount(_:_:), SKIndexGetDocumentTermFrequency(_:_:_:), and SKIndexGetTermDocumentCount(_:_:). However, in typical use this won’t be an issue, because applications call these functions after a search, and you must call SKIndexFlush before a search.

## See Also

### Managing Indexes

- [SKIndexAddDocumentWithText(_:_:_:_:)](coreservices/1444518-skindexadddocumentwithtext.md)
- [SKIndexFlush(_:)](coreservices/1450667-skindexflush.md)
- [SKIndexCompact(_:)](coreservices/1443628-skindexcompact.md)
- [SKIndexGetDocumentCount(_:)](coreservices/1449093-skindexgetdocumentcount.md)
- [SKIndexGetMaximumDocumentID(_:)](coreservices/1444628-skindexgetmaximumdocumentid.md)
- [SKIndexGetMaximumTermID(_:)](coreservices/1444278-skindexgetmaximumtermid.md)
- [SKIndexDocumentIteratorCreate(_:_:)](coreservices/1446189-skindexdocumentiteratorcreate.md)
- [SKIndexDocumentIteratorCopyNext(_:)](coreservices/1442212-skindexdocumentiteratorcopynext.md)
- [SKIndexDocumentIteratorGetTypeID()](coreservices/1443022-skindexdocumentiteratorgettypeid.md)
- [SKIndexGetAnalysisProperties(_:)](coreservices/1443461-skindexgetanalysisproperties.md)
- [SKIndexMoveDocument(_:_:_:)](coreservices/1449899-skindexmovedocument.md)
- [SKIndexRemoveDocument(_:_:)](coreservices/1444375-skindexremovedocument.md)
- [SKIndexRenameDocument(_:_:_:)](coreservices/1448935-skindexrenamedocument.md)
- [SKIndexSetMaximumBytesBeforeFlush(_:_:)](coreservices/1448696-skindexsetmaximumbytesbeforeflus.md)
- [SKIndexGetMaximumBytesBeforeFlush(_:)](coreservices/1445329-skindexgetmaximumbytesbeforeflus.md)
