<!--
{
  "availability" : [
    "iOS: 5.0.0 -",
    "iPadOS: 5.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.4.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/NSMetadataQueryDelegate/metadataQuery(_:replacementObjectForResultObject:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(pl)NSMetadataQueryDelegate(im)metadataQuery:replacementObjectForResultObject:"
  },
  "title" : "metadataQuery(_:replacementObjectForResultObject:)"
}
-->

# metadataQuery(_:replacementObjectForResultObject:)

Returns a different object for a given query result object.

```
optional func metadataQuery(_ query: NSMetadataQuery, replacementObjectForResultObject result: NSMetadataItem) -> Any
```

## Parameters

`query`

The query that produced the result object to replace.

`result`

The query result object to replace.

## Return Value

Object that replaces the query result object.

## Discussion

By default query result objects are instances of the [`NSMetadataItem`](/documentation/Foundation/NSMetadataItem) class. By implementing this method, you can return an object of a different class type for the specified result object.

## See Also

  [File Metadata Search Programming Guide](https://developer.apple.com/library/archive/documentation/Carbon/Conceptual/SpotlightQuery/Concepts/Introduction.html#//apple_ref/doc/uid/TP40001841)



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)