3

I see people are using the FileManager and NSMetadataQuery to retrieve filenames in iCloud, when programming an IOS/Swift app. Which is better, and safer ? It seems Apple wants you to use NSMetadataQuery, but the advantage for the FileManager, is that the code will also work on the IOS device as well as iCloud, and also provides file attributes in addition to filenames.

For example using FileManager it can be done this way:

let contents =
    try FileManager.default.contentsOfDirectory(at: directoryURL,
                                                includingPropertiesForKeys: nil,
                                                options: [.skipsHiddenFiles])
for file in contents {
    …
}

Using NSMetadataQuery like this:

self.nsMetadataQuery!.predicate = NSPredicate(format: "%K LIKE '*'",
                //                                              argumentArray: [NSMetadataItemPathKey, path, NSMetadataItemFSNameKey])

1 Answer 1

0

It seems, that Apple Docs encourage you to use NSMetadataQuery for searching documents in iCloud Container instead of File Manager API.

So probably NSMetaDataQuery is the way to go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.