NSFileVersion doesn't work in IOS simulator?

I have the following code - you can see where I had to comment out the code on the simulator. Is this expected? The code works perfectly fine on a physical iPad device. Is it documented somewhere that NSFileVersion doesn't work with non-local versions in the simulator?

   func loadPreviewDirectly(
        from version: NSFileVersion,
        completion: @escaping (CIImage?) -> Void
    ) {
        let versionURL = version.url
        let access = versionURL.startAccessingSecurityScopedResource()
        defer { if access { versionURL.stopAccessingSecurityScopedResource() } }

        print("Loading version: \(version.persistentIdentifier) | Local: \(version.hasLocalContents)")

        // 1. SIMULATOR CATCH: If running in simulator and the file is missing, it will never download.
#if targetEnvironment(simulator)
        if !version.hasLocalContents {
            print("⚠️ iOS Simulator cannot materialize remote NSFileVersions. Fallback triggered.")
            // You cannot test remote versions here. For testing on the simulator,
            // test with a version where version.hasLocalContents == true (created locally in this session).
            DispatchQueue.main.async { completion(nil) }
            return
        }
#endif

        let coordinator = NSFileCoordinator()
        var coordinationError: NSError?

        // 2. Wrap everything in a sequential reading coordination
        coordinator.coordinate(readingItemAt: versionURL, options: [], error: &coordinationError) { readURL in
            let image = CIImage(contentsOf: readURL)
            DispatchQueue.main.async {
                completion(image)
            }
        }
        if let error = coordinationError {
            DispatchQueue.main.async {
                self.errorMessage = error.localizedDescription
                completion(nil)
            }
        }
    }
Answered by DTS Engineer in 894132022

I have the following code - you can see where I had to comment out the code on the simulator. Is this expected?

I haven't looked closely at the specific details, but the short answer is that, yes, it's almost certainly expected. Architecturally, the simulator is basically a "port" of iOS to macOS, not a fully functional OS that's running independently. This works fine for its primary function (basic UI development and basic functional testing), but it creates a problem with lower-level systems where the feature overlaps with existing macOS functionality and/or would require implementing parts of iOS that were otherwise not implemented. In most of those cases, the simulator tends to simply avoid the entire issue by not implementing the functionality at all.

The code works perfectly fine on a physical iPad device. Is it documented somewhere that NSFileVersion doesn't work with non-local versions in the simulator?

No, probably not. The simulator has always been considered a development aid, so these details have never been documented to the same extent as the broader system.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Accepted Answer

I have the following code - you can see where I had to comment out the code on the simulator. Is this expected?

I haven't looked closely at the specific details, but the short answer is that, yes, it's almost certainly expected. Architecturally, the simulator is basically a "port" of iOS to macOS, not a fully functional OS that's running independently. This works fine for its primary function (basic UI development and basic functional testing), but it creates a problem with lower-level systems where the feature overlaps with existing macOS functionality and/or would require implementing parts of iOS that were otherwise not implemented. In most of those cases, the simulator tends to simply avoid the entire issue by not implementing the functionality at all.

The code works perfectly fine on a physical iPad device. Is it documented somewhere that NSFileVersion doesn't work with non-local versions in the simulator?

No, probably not. The simulator has always been considered a development aid, so these details have never been documented to the same extent as the broader system.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

Hmm, that's unfortunate - at a minimum you would think the list of things that are expected to be broken would be documented. Thank you for taking the time to respond.

Hmm, that's unfortunate - at a minimum, you would think the list of things that are expected to be broken would be documented. Thank you for taking the time to respond.

Unfortunately, this is harder than it sounds, due to how the simulator was created and evolved. When it was originally introduced, there wasn't really any need for such a list because it was WILDLY obvious that the simulator did not accurately recreate iOS. Not only were many services missing/unimplemented, Macs at the time were SO much faster than iPhones that it was fairly easy to create an app that worked perfectly fine in the simulator and was completely unusable on device. It was fairly clear to most developers that the simulator's role was simply to make things like getting an interface up and running easier and faster, not to serve as any kind of useful testing platform.

What's complicated things since then is that the performance (and platform) of our machines have slowly converged, while the simulator has slowly moved closer to iOS's implementation. However, this has largely been an informal process often driven by implementation "convenience", not an explicit formal effort to make the simulator more "real". Even worse, there's still enough divergence between the simulator and iOS (particularly across our full Mac hardware range[1]) that we simply can't endorse it as a "real" testing platform. There are many cases where it does work fine for that, but there are enough cases where it DOESN'T at all work that we can't really recommend it as a general testing tool.

All of that is why we don't already have such a list and haven't created one.

[1] For example, the CPU and memory "spread" of macOS hardware means that the gap between what's possible on our lowest end and highest end machines can be pretty extreme.

__
Kevin Elliott
DTS Engineer, CoreOS/Hardware

That's an understandable position. Thank you.

NSFileVersion doesn't work in IOS simulator?
 
 
Q