NSMetadataQuery on tvOS

I wanted to use NSMetadataQuery on tvOS to query for a file changed through iCloud. However, the app crashes directly when instantiating a NSMetadataQuery object. Documentation says its available since tvOS 9.0. https://developer.apple.com/documentation/foundation/nsmetadataquery

It crashes in the simulator (tvOS 15.4 and tvOS 16) as well as on a real device with the latest tvOS version.

I just created it like this:

private let metadataQuery = NSMetadataQuery()

Is it not possible to use NSMetadataQuery on tvOS?

I also filed a feedback FB11422512

The fact that NSMetadataQuery crashes on tvOS is most definitely a bug. Thanks for filing FB11422512 about that.

However, as things currently stand the underlying support for NSMetadataQuery is simply not present on tvOS. This specific crash is coming out of the -[NSMetadataQuery dealloc] method, which is running because -[NSMetadataQuery init] has failed because of missing infrastructure. If -[NSMetadataQuery init] hadn’t crashed, it would’ve returned nil [1].

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

[1] In Objective-C. Swift would have taken one look at that nil and promptly trapped.

NSMetadataQuery on tvOS
 
 
Q