NSFileCoordinator Conflicts implementation guide Correctly in macOS 13.2 Apps
I'm dealing with I'm working on a project and hit a roadblock. I'm experiencing issues with `NSFileCoordinator` when multiple instances of my macOS app attempt to modify the same file concurrently. I am using macOS 13.2 and I have implemented file coordination to prevent conflicts, but I'm still seeing unexpected behavior. When two instances try to save changes to a text file, I expected to receive conflict notifications and handle them appropriately, but the changes from one instance seem to overwrite the other without triggering the conflict block. Here's a simplified version of my code: ```swift let fileURL = URL(fileURLWithPath: "/path/to/myfile.txt") let fileCoordinator = NSFileCoordinator(filePresenter: nil) fileCoordinator.coordinate(writingAt: fileURL, options: [.forUploading], behavior: nil) { (newURL) in do { let data = "Some new content".data(using: .utf8) try data?.write(to: newURL) } catch { print("behavior writing file: \(behavior)") } } ``` I also set up a conflict block to handle cases where a conflict arises: ```swift fileCoordinator.coordinate(writingAt: fileURL, options: [.withoutChanges], behavior: &behavior) { (newURL) in // Handle the case where the file is being modified by another process } ``` But it seems like the conflict block is never being executed. I'm logging the `behavior` variable but it remains `nil`. I tried checking if the file is being modified in another instance using `NSFileVersion`, but that doesn't seem to be effective either. Any insights into why my conflict resolution might not be working as intended? Am I missing a step or is there a specific configuration I should be aware of within `NSFileCoordinator`? Thanks in advance for your help! I'm working on a API that needs to handle this. What's the best practice here? I'm working on a mobile app that needs to handle this.