Debugging files in iOS
A couple of tips on verifying that your files and folder operations do what you expect.
Published: March 20, 2022 Sponsored App StoreI bet you have already used FileManager at least a few times. It is pretty straightforward, but unless your app is a proper file manager with lists of all files and similar, it is a bit complex to take an unfiltered look at the underlying files.
Perhaps you are working with audio files and need to verify they are correctly saved or generate images that you want to see quickly. Whatever the case, there are ways to view the files directly to confirm your assumptions.
Let's look at the options.
Utilize the built-in Files app
iOS has a capable files browser for some time now. We can leverage it to inspect the Documents folder of our app. Examining files has many benefits over just printing the folder's contents to the Xcode console.
You can see files metadata and, more importantly, preview many standard formats without needing specialized apps.
By default Documents folder of your app is hidden from users. But with a couple of Info.plist
keys, you can expose it inside the Files app.
I have older blog post with all the details you need if you opt for this approach.
The next step could be adding a debug-only button to your app that quickly opens the Files app inside your app's Documents. I have another blog post with the specific URL scheme you need to use.
Other folders are available for your app, but these cannot be exposed in Files. If you want to use a different folder, I recommend switching to Documents in debug builds to remedy this limitation.
Inspect the entire apps data container
This is more time-intensive each time you want to view a "snapshot" of your app's files but doesn't require any modifications to your project.
You can select any of your deployed apps in the Devices and Simulators window of Xcode (available from the menu bar menu under Window). Under the small "three dots" icon (I believe before Xcode 13.3, this was a gear icon) - below the list of apps -there is an option to download the container for the particular app.
It takes a bit of time. You can then head to Downloads, right-click this special archive with a .appdata
extension, and select View package contents. Then open "AppData" folder, and assuming you have saved anything into your app's Document folder, you should see the "Documents" folder here and all its content.
And if you are using hidden folders or files, using the shortcut Command + Shift + dot in Finder, you can toggle visibility.