---
title: "SKIndexCompact(_:)"
framework: Core Services
role: symbol
role_heading: Function
platforms: [macOS 10.3+]
path: coreservices/1443628-skindexcompact
---

# SKIndexCompact(_:)

Invokes all pending updates associated with an index, compacts the index if compaction is needed, and commits all changes to backing store.

## Declaration

```swift
func SKIndexCompact(_ inIndex: SKIndex!) -> Bool
```

## Parameters

- `inIndex`: The index you want to compact.

## Return Value

Return Value A Boolean value of true on success, or false on failure.

## Discussion

Discussion Over time, as document URL objects (of type SKDocument) and associated contents get added to and removed from an index, the index’s disk or memory footprint may grow due to fragmentation. Compacting can take a significant amount of time. Do not call SKIndexCompact(_:) on the main thread in an application with a user interface. Call it only if the index is significantly fragmented and according to the needs of your application. Calling SKIndexCompact(_:) changes the block allocation for an index’s backing store. Close all clients of an index before calling this function.

## See Also

### Managing Indexes

- [SKIndexAddDocumentWithText(_:_:_:_:)](coreservices/1444518-skindexadddocumentwithtext.md)
- [SKIndexAddDocument(_:_:_:_:)](coreservices/1444897-skindexadddocument.md)
- [SKIndexFlush(_:)](coreservices/1450667-skindexflush.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)
