Easy simulator data access

When developing for iOS it’s often useful to navigate to the files you create in the simulator so you can inspect everything is how you expect it to be. The location of where the files live on disk has changed throughout the years but one thing has remained constant - it’s awkward to locate where the files are. Now days simctl and excellent wrappers around it like Control Room help make it simpler to locate your files but there is still too much friction. The friction of locating files becomes even more evident when working in a team where everyone has different tooling and levels of comfort with the various options.

Here’s a hack solution that avoids any third party tooling and keeps things consistent for all members on the team. The general idea is to detect we are running in a simulator and then drop a symlink on your desktop. Checking out the environment variables available when running in the simulator reveals there is all the information we need to make this happen.

#if targetEnvironment(simulator)
    let environment = ProcessInfo.processInfo.environment
        let rootFolder = environment["SIMULATOR_HOST_HOME"].map(URL.init(fileURLWithPath:))?.appendingPathComponent("Desktop/SimulatorData"),
        let simulatorHome = environment["HOME"].map(URL.init(fileURLWithPath:)),
        let simulatorVersion = environment["SIMULATOR_RUNTIME_VERSION"],
        let simulatorName = environment["SIMULATOR_DEVICE_NAME"],
        let productName = Bundle.main.infoDictionary?["CFBundleName"]
        let symlink = rootFolder.appendingPathComponent("\(productName) \(simulatorName) (\(simulatorVersion))")
        let fileManager = FileManager.default
        try? fileManager.createDirectory(at: rootFolder, withIntermediateDirectories: true)
        try? fileManager.removeItem(at: symlink)
        try? fileManager.createSymbolicLink(at: symlink, withDestinationURL: simulatorHome)

Now whenever you run your app in the simulator a fresh new symlink will be created on your mac’s desktop making it really quick to go from thinking “I need to look in my apps data folder” to being there in Finder.

Wrap up

This problem has annoyed me for a long time (I wrote a Ruby gem 10 years ago to help with locating simulator directories 1). I’ve used multiple tools over the years from my gem, to various third party apps and now I mostly use simctl directly. This is my new favourite solution that requires no third parties or searching through my zsh history - it’s only taken 10 years of pushing this particular stone up a hill to come up with this idea 🤦🏼‍♂️.

  1. https://rubygems.org/gems/sidir/versions/0.0.5 don’t use