<!--
{
  "availability" : [
    "Swift: 6.2.0 -",
    "Xcode: 26.0.0 -",
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "swift: 6.0.0 -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Testing",
  "identifier" : "/documentation/Testing/Trait/compactMapIssues(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Swift Testing",
      "Testing"
    ],
    "preciseIdentifier" : "s:7Testing5TraitPA2A013IssueHandlingB0VRszrlE16compactMapIssuesyAeA0C0VSgAHYbcFZ"
  },
  "title" : "compactMapIssues(_:)"
}
-->

# compactMapIssues(_:)

Constructs an trait that transforms issues recorded by a test.

```
static func compactMapIssues(_ transform: @escaping @Sendable (Issue) -> Issue?) -> Self
```

## Parameters

`transform`

A closure called for each issue recorded by the test
this trait is applied to. It is passed a recorded issue, and returns
an optional issue to replace the passed-in one.

## Return Value

An instance of [`IssueHandlingTrait`](/documentation/Testing/IssueHandlingTrait) that transforms issues.

## Discussion

The `transform` closure is called synchronously each time an issue is
recorded by the test this trait is applied to. The closure is passed the
recorded issue, and if it returns a non-`nil` value, that will be recorded
instead of the original. Otherwise, if the closure returns `nil`, the
issue is suppressed and will not be included in the results.

The `transform` closure may be called more than once if the test records
multiple issues. If more than one instance of this trait is applied to a
test (including via inheritance from a containing suite), the `transform`
closure for each instance will be called in right-to-left, innermost-to-
outermost order, unless `nil` is returned, which will skip invoking the
remaining traits’ closures.

Within `transform`, you may access the current test or test case (if any)
using [`current`](/documentation/Testing/Test/current) [`current`](/documentation/Testing/Test/Case/current), respectively. You may also
record new issues, although they will only be handled by issue handling
traits which precede this trait or were inherited from a containing suite.

> Note: `transform` will never be passed an issue for which the value of
> ``doc://org.swift.testing/documentation/Testing/Issue/kind-swift.property`` is ``doc://org.swift.testing/documentation/Testing/Issue/Kind-swift.enum/system``, and may not return such an
> issue.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)