---
title: NSMetadataQuery
framework: foundation
role: symbol
role_heading: Class
path: foundation/nsmetadataquery
---

# NSMetadataQuery

A query that you perform against Spotlight metadata.

## Declaration

```swift
class NSMetadataQuery
```

## Overview

Overview The NSMetadataQuery class encapsulates the functionality provided by the MDQuery opaque type for querying the Spotlight metadata. NSMetadataQuery objects provide metadata query results in several ways: As individual attribute values for requested attributes. As value lists that contain the distinct values for given attributes in the query results. As a result array proxy, containing all the query results. This is suitable for use with Cocoa bindings. As a hierarchical collection of results, grouping together items with the same values for specified grouping attributes. This is also suitable for use with Cocoa bindings. Queries have two phases: the initial gathering phase that collects all currently matching results and a second live-update phase. By default, the receiver has no limitation on its search scope. Use the searchScopes property to customize. By default, notification of updated results occurs at 1.0 seconds. Use the notificationBatchingInterval property to customize. You must set a predicate with the predicate property before starting a query.

## Topics

### Configuring queries

- [searchScopes](foundation/nsmetadataquery/searchscopes.md)
- [predicate](foundation/nsmetadataquery/predicate.md)
- [sortDescriptors](foundation/nsmetadataquery/sortdescriptors.md)
- [valueListAttributes](foundation/nsmetadataquery/valuelistattributes.md)
- [groupingAttributes](foundation/nsmetadataquery/groupingattributes.md)
- [notificationBatchingInterval](foundation/nsmetadataquery/notificationbatchinginterval.md)
- [delegate](foundation/nsmetadataquery/delegate.md)
- [searchItems](foundation/nsmetadataquery/searchitems.md)

### Running queries

- [isStarted](foundation/nsmetadataquery/isstarted.md)
- [start()](foundation/nsmetadataquery/start().md)
- [isGathering](foundation/nsmetadataquery/isgathering.md)
- [isStopped](foundation/nsmetadataquery/isstopped.md)
- [stop()](foundation/nsmetadataquery/stop().md)

### Getting query results

- [results](foundation/nsmetadataquery/results.md)
- [resultCount](foundation/nsmetadataquery/resultcount.md)
- [result(at:)](foundation/nsmetadataquery/result(at:).md)
- [index(ofResult:)](foundation/nsmetadataquery/index(ofresult:).md)
- [groupedResults](foundation/nsmetadataquery/groupedresults.md)
- [NSMetadataQueryResultGroup](foundation/nsmetadataqueryresultgroup.md)
- [enumerateResults(_:)](foundation/nsmetadataquery/enumerateresults(_:).md)
- [enumerateResults(options:using:)](foundation/nsmetadataquery/enumerateresults(options:using:).md)
- [valueLists](foundation/nsmetadataquery/valuelists.md)
- [NSMetadataQueryAttributeValueTuple](foundation/nsmetadataqueryattributevaluetuple.md)
- [value(ofAttribute:forResultAt:)](foundation/nsmetadataquery/value(ofattribute:forresultat:).md)
- [enableUpdates()](foundation/nsmetadataquery/enableupdates().md)
- [disableUpdates()](foundation/nsmetadataquery/disableupdates().md)
- [operationQueue](foundation/nsmetadataquery/operationqueue.md)

### Working with notifications

- [NSMetadataQueryDidFinishGathering](foundation/nsnotification/name-swift.struct/nsmetadataquerydidfinishgathering.md)
- [NSMetadataQueryDidStartGathering](foundation/nsnotification/name-swift.struct/nsmetadataquerydidstartgathering.md)
- [NSMetadataQueryDidUpdate](foundation/nsnotification/name-swift.struct/nsmetadataquerydidupdate.md)
- [NSMetadataQueryGatheringProgress](foundation/nsnotification/name-swift.struct/nsmetadataquerygatheringprogress.md)

### Working with notification messages

- [NSMetadataQuery.DidFinishGatheringMessage](foundation/nsmetadataquery/didfinishgatheringmessage.md)
- [NSMetadataQuery.DidStartGatheringMessage](foundation/nsmetadataquery/didstartgatheringmessage.md)

### Constants

- [Metadata Query Search Scopes](foundation/metadata-query-search-scopes.md)
- [Content Relevance](foundation/content-relevance.md)
- [Keys for Use with a Notification Info Dictionary](foundation/keys-for-use-with-a-notification-info-dictionary.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### File Search

- [NSMetadataQueryDelegate](foundation/nsmetadataquerydelegate.md)
- [NSMetadataItem](foundation/nsmetadataitem.md)
