Is there any way to see the file system on the iOS simulator?

后端 未结 12 1694
清歌不尽
清歌不尽 2020-11-30 17:15

Is there any way to browse the file system of a currently running or just killed iOS simulator? I\'d settle for being able to see a specific app\'s files if there\'s a way t

12条回答
  •  一个人的身影
    2020-11-30 17:27

    For Swift 4.2 and higher, print an easy to use path:

    #if targetEnvironment(simulator)
        print("::::: SIMULATOR :::::")
        if let documentsPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path {
            print("App Documents Directory:\n\(documentsPath)\n")
        }
    #endif
    

    ... in a source code location such as:

    func application(
        _ application: UIApplication, 
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        // ...
        return true
    }
    

    Use the resulting path with cd or open on the terminal command line. Or, paste the path in the shift-cmd-G "Go To Folder…" Finder prompt.

    Related answer which includes older language versions: Document Directory Path of iOS 8 Beta Simulator

提交回复
热议问题