---
title: "MDQueryGetResultAtIndex(_:_:)"
framework: coreservices
role: symbol
role_heading: Function
path: coreservices/1413055-mdquerygetresultatindex
---

# MDQueryGetResultAtIndex(_:_:)

Returns the current result at the given index.

## Declaration

```swift
func MDQueryGetResultAtIndex(_ query: MDQuery!, _ idx: CFIndex) -> UnsafeRawPointer!
```

## Parameters

- `query`: The query.
- `idx`: The index into the query's result list. If the index is negative, or is equal to or larger than the current number of results in the query, the behavior is undefined.

## Return Value

Return Value Returns the MDItemRef currently at the given index, or if a result-creation function has been set, returns the result returned by that function.

## Discussion

Discussion This function causes the result object to be created if it hasn't been created already. For performance reasons you should only request objects that you require. If possible, call this function to fetch only the results you need to display or otherwise process.  Note that the index of a particular result can change over time if the query is configured to allow live-updates.

## See Also

### Getting Query Result Values

- [MDQueryCopyValuesOfAttribute(_:_:)](coreservices/1413105-mdquerycopyvaluesofattribute.md)
- [MDQueryGetAttributeValueOfResultAtIndex(_:_:_:)](coreservices/1413046-mdquerygetattributevalueofresult.md)
- [MDQueryGetCountOfResultsWithAttributeValue(_:_:_:)](coreservices/1413009-mdquerygetcountofresultswithattr.md)
- [MDQueryGetIndexOfResult(_:_:)](coreservices/1413093-mdquerygetindexofresult.md)
- [MDQueryGetResultCount(_:)](coreservices/1413008-mdquerygetresultcount.md)
- [MDQuerySetSortComparatorBlock(_:_:)](coreservices/1413021-mdquerysetsortcomparatorblock.md)
