How to Inspect Core Data Database Contents in iOS Simulator

How to Inspect Core Data Database Contents in iOS Simulator

Written by

in

Quick answer: Core Data stores SQLite files in the simulator’s sandbox at ~/Library/Developer/CoreSimulator/Devices//data/Containers/Data/Application//Documents/. Open the .sqlite file with DB Browser for SQLite, Liya, or use Xcode’s Debug Navigator > View Memory to inspect contents.

Why this happens

Core Data uses SQLite as its default persistent store, but the database file lives inside the app’s sandboxed container. Unlike macOS apps where you can browse the Documents folder freely, iOS Simulator apps are isolated in a device-specific directory under ~/Library/Developer/CoreSimulator/Devices/. Each simulator device gets a unique UUID, and each app install gets another UUID, so the path changes every time you reset the simulator or reinstall the app. This makes it non-obvious where to find the .sqlite file and how to open it safely without corrupting the store.

Additionally, Core Data may use Write-Ahead Logging (WAL) mode, which creates -wal and -shm files alongside the main .sqlite file. You must copy or open all three together, otherwise you’ll see stale data or an empty database.

How to fix it

1. Locate the database with a one-liner in Terminal

The fastest way to find the current app’s container is to ask simctl. Run this while your app is installed on the booted simulator:

xcrun simctl get_app_container booted <your.bundle.identifier> data

Replace <your.bundle.identifier> with your actual bundle ID (e.g., com.example.MyApp). The command prints the full path to the app’s Data folder. Your SQLite file is usually in Documents/ or Library/Application Support/ inside that container.

Example output:

/Users/you/Library/Developer/CoreSimulator/Devices/A1B2C3D4-.../data/Containers/Data/Application/E5F6G7H8-...

Then open that folder in Finder:

open $(xcrun simctl get_app_container booted com.example.MyApp data)/Documents

2. Open the SQLite file with DB Browser for SQLite (free, cross-platform)

  1. Install DB Browser for SQLite via Homebrew (brew install --cask db-browser-for-sqlite) or download the DMG.
  2. In Finder, navigate to the container’s Documents folder (from step 1).
  3. Drag your .sqlite file onto DB Browser. It automatically detects and loads the -wal/-shm sidecar files if present.
  4. Use the Browse Data tab to inspect tables. Core Data tables are named Z<ENTITYNAME> (e.g., ZUSER, ZNOTE). Columns are prefixed with Z_ (primary key), Z_OPT (optimistic locking), then your attributes (ZNAME, ZCREATEDAT, etc.).

Tip: If you see zero rows but know data exists, the WAL file hasn’t been checkpointed. In DB Browser, choose File → Write Changes or run a manual checkpoint:

PRAGMA wal_checkpoint(RESTART);

3. Use Liya (Mac App Store) for a native macOS experience

Liya is a lightweight SQLite viewer designed for macOS. After installing from the Mac App Store:

  1. Open Liya.
  2. Press ⌘O and navigate to the simulator container’s Documents folder.
  3. Select the .sqlite file. Liya reads the WAL files automatically.
  4. Double-click a table to view rows. Liya shows Core Data’s internal columns (Z_PK, Z_ENT, Z_OPT) alongside your attributes.

Liya also lets you run raw SQL queries, which is handy for testing fetch predicates.

4. Inspect via Xcode’s Debug Navigator (no external tools)

Since Xcode 13, you can view Core Data stores directly in the debugger:

  1. Run your app on the simulator.
  2. Open the Debug Navigator (⌘7).
  3. At the bottom, click the View Memory button (gauge icon) → Core Data.
  4. A list of persistent stores appears. Click one to see entity counts and fetch a sample of objects.

This method shows live managed objects, not raw SQLite rows, so you see the object graph as Core Data presents it (including relationships and transient properties).

5. Automate with a Dock shortcut (for frequent checks)

Create a small Automator Quick Action that opens the latest simulator container in DB Browser:

  1. Open Automator → New → Quick Action.
  2. Set Workflow receives to no input in any application.
  3. Add Run Shell Script (Shell: /bin/zsh, Pass input: as arguments):
# Find the most recently booted simulator device
DEVICE=$(xcrun simctl list devices | grep -E 'Booted' | head -1 | sed -E 's/.*\(([^)]+)\).*/\1/')
if [[ -z "$DEVICE" ]]; then
  osascript -e 'display notification "No booted simulator found" with title "Core Data Inspector"'
  exit 1
fi

# Find the most recently modified app container (assumes your app is the latest)
CONTAINER=$(find ~/Library/Developer/CoreSimulator/Devices/"$DEVICE"/data/Containers/Data/Application -maxdepth 1 -mindepth 1 -type d -name '*.app' -prune -o -type d -print | xargs ls -td | head -1)

# Locate the first .sqlite file in Documents or Library/Application Support
SQLITE=$(find "$CONTAINER" -name '*.sqlite' -not -name '*-wal' -not -name '*-shm' | head -1)

if [[ -n "$SQLITE" ]]; then
  open -a "DB Browser for SQLite" "$SQLITE"
else
  osascript -e 'display notification "No SQLite file found" with title "Core Data Inspector"'
fi
  1. Save as Open Core Data DB.
  2. In System Settings → Keyboard → Keyboard Shortcuts → Services, assign a shortcut (e.g., ⌃⌘D).

Now pressing the shortcut while the simulator is running opens your database instantly.

How to prevent it

  • Enable SQL debug logging during development: add -com.apple.CoreData.SQLDebug 1 (or 2, 3 for more detail) to Arguments Passed On Launch in your scheme. You’ll see every SELECT, INSERT, UPDATE in the console.
  • Use a dedicated debug build configuration that copies the database to a known location (e.g., /tmp/MyApp.sqlite) on app launch for quick access.
  • Avoid modifying the SQLite file directly while the app is running. Core Data caches data in memory; external writes cause inconsistencies or crashes.
  • Reset the simulator (Device → Erase All Content and Settings) when schema migrations fail, rather than manually deleting files.
  • Test on device occasionally — simulator paths differ from device sandbox paths, and file protection classes behave differently.

FAQ

Why do I see an empty database even after inserting data?

Core Data uses WAL mode by default. Changes live in the -wal file until a checkpoint merges them into the main .sqlite. Either wait for the automatic checkpoint (after ~1000 pages or when the last connection closes), call try context.save() followed by try persistentStoreCoordinator.checkpoint() in code, or run PRAGMA wal_checkpoint(RESTART); in your SQLite viewer.

Can I inspect the database on a physical iPhone?

Not directly. The device sandbox is not accessible via Finder. Options: (1) Use Xcode’s Devices and Simulators window → Download Container for your app, then open the downloaded .xcappdata package (right-click → Show Package Contents → AppData/Documents). (2) Enable Network Debugging and use a tool like Flipper with the Core Data plugin to inspect over USB/Wi-Fi.

My app uses multiple configurations or stores — how do I know which file to open?

Print the store URL at runtime:

if let storeURL = persistentContainer.persistentStoreDescriptions.first?.url {
    print("Core Data store: \(storeURL)")
}

Run the app and copy the printed path. Each configuration gets its own .sqlite file (e.g., MyApp.sqlite, MyApp_Cache.sqlite).

Sources & credits

Parts of this guide are adapted from content licensed under CC BY-SA 4.0; this article is shared under the same license.