---
title: iOS
description: >-
  Apply LLVM coverage flags through the CocoaPods helper, flush from the
  TurboModule, and export LCOV from the iOS Simulator.
---
> ## Documentation Index
> Fetch the complete documentation index at: https://docs.page/invertase/react-native-coverage/llms.txt
> Use this file to discover all available pages before exploring further.

The [test app](/coverage#dedicated-test-app) must run the New Architecture; the TurboModule autolinks through the `Coverage.podspec` file.

## Expo

1. Add the config plugin. It adds the `Podfile` helper call for you:

```json
{
  "expo": {
    "plugins": [
      [
        "react-native-coverage",
        {
          "frameworkNamePrefixes": ["MyLib"],
          "forceDynamicFrameworks": false
        }
      ]
    ]
  }
}
```

2. Set up the native iOS project:

```sh
npx expo prebuild
cd ios && pod install
```

Under Expo, keep `forceDynamicFrameworks` `false`. For more information, see [Static and dynamic frameworks](/integration/ios#static-and-dynamic-frameworks).

## React Native CLI

Call the helper from the `Podfile`:

```ruby
require_relative '../node_modules/react-native-coverage/cocoapods/coverage_post_install'

# After use_expo_modules!, when present, so the restore runs after Expo's static downgrade
ReactNativeCoverage.install_installer_hooks!

post_install do |installer|
  ReactNativeCoverage.apply_post_install!(
    installer,
    framework_name_prefixes: ['MyLib'],
    force_dynamic_frameworks: true
  )
end
```

The helper does the following:

- Applies `-fprofile-instr-generate` and `-fcoverage-mapping`, with the matching link flags, to the app target and to the pods that match `framework_name_prefixes`.
- Regenerates the `ios/CoverageConfig.h` file from `framework_name_prefixes`, so the flusher can read the matching images.
- Restores `Pod::BuildType.dynamic_framework` for the Coverage pods and matched pods when Expo forced `static_library` and `force_dynamic_frameworks` is `true`.

Do not add the LLVM flags by editing the `Podfile` with a regular expression. The helper is the supported path, and the Expo plugin calls the same helper.

## Static and dynamic frameworks

The flusher reads LLVM counters from the `LINKEDIT` section of each loaded image: the main executable, and every framework whose name starts with one of `frameworkNamePrefixes`.

- With static libraries, which is Expo's default, your pods are merged into the app binary. The main executable carries the counters, and one LCOV covers everything.
- With dynamic frameworks, each framework is its own image with its own counters. `frameworkNamePrefixes` selects which images the flusher reads.

Only when React itself builds as dynamic frameworks, as in this repository's `example-dynamic/` app, set `forceDynamicFrameworks` to `true`. Under Expo, `React-Core` is a static library, and CocoaPods rejects a dynamic Coverage pod that depends on a static `React-Core`. Leave the value `false` there and the Coverage pods stay static libraries merged into the app.

## Pull and export

When the suite ends, `Coverage.flush()` writes the `.profraw` files into the simulator container. On the host, pull the profiles, export LCOV, and assert coverage:

```sh
rn-coverage ios pull --device UDID                   # copies the .profraw files out of the container
rn-coverage ios export --derived-data DERIVED_DATA_PATH  # merges them and writes LCOV
rn-coverage ios report --derived-data DERIVED_DATA_PATH  # llvm-cov report, optional
rn-coverage ios summary --derived-data DERIVED_DATA_PATH # llvm-cov summary, optional
rn-coverage assert                                   # exits 2 when the LCOV has no matched hits
```

Build the test app with `-derivedDataPath` so `--derived-data` points at a folder you control. The CLI handles universal (multi-arch) simulator binaries for you; `--arch` overrides the selection. For more information, see [CLI](/reference/cli).
