Last active
November 23, 2022 07:28
-
-
Save samsonjs/9f460ae11c91254168a996ae896b776e to your computer and use it in GitHub Desktop.
Paul Samuel’s code for symlinking simulator directories to make them more accessible
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Courtesy of https://paul-samuels.com/blog/2022/10/12/easy-simulator-data-access/ | |
#if targetEnvironment(simulator) | |
let environment = ProcessInfo.processInfo.environment | |
if | |
let hostHome = environment["SIMULATOR_HOST_HOME"].map(URL.init(fileURLWithPath:)), | |
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 deviceDirectoryName = "\(productName) \(simulatorName) (\(simulatorVersion))" | |
let symlinkFolder = hostHome.appending(component: "SimulatorData/") | |
let symlink = symlinkFolder.appending(component: deviceDirectoryName) | |
do { | |
let fm = FileManager.default | |
try fm.createDirectory(at: symlinkFolder, withIntermediateDirectories: true) | |
_ = try? fm.removeItem(at: symlink) | |
try fm.createSymbolicLink(at: symlink, withDestinationURL: simulatorHome) | |
} catch { | |
NSLog("[ERROR] Failed to initialize simulator symlink: \(error)") | |
NSLog("[ERROR] rootFolder=\(symlinkFolder) symlink=\(symlink)") | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment