Post

Replies

Boosts

Views

Activity

Reply to how to check if a file is in trash or not
The documentation for getRelationship says: “For example, to discover if a file is contained by a Trash directory, call [fileManager getRelationship:&result ofDirectory:NSTrashDirectory inDomain:0 toItemAtURL:url error:&error].” However, I can’t get the following Swift code to work:     var relationship: URLRelationship = .contains     getRelationship(&relationship, of: .trashDirectory,                                 in: SearchPathDomainMask(rawValue: 0),                                 toItemAt: url) After finding your comment above, I tried using url(for:in:appropriateFor:create:) to get the trash directory, but can’t get that to work either (iOS 14.0.1, Xcode 12.0.1). The following code always fails with "The requested operation couldn’t be completed because the feature is not supported.":     let fileManager = FileManager.default     let docURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask).first!     do {         let trashURL = try fileManager.url(for: .trashDirectory, in: .userDomainMask,                                            appropriateFor: docURL, create: false)         print("trashURL = \(trashURL)")     }     catch {         print("could not get trashURL: \(error.localizedDescription)")     } Is this API not working, or am I doing something wrong? Thanks!
Oct ’20