Swizzling

Learn which features use swizzling

The Cocoa SDK uses swizzling to provide some features out of the box without boilerplate code. The following features use swizzling:

macOS

iOS, tvOS and Catalyst

Since Cocoa 7.5.0, you can opt out of swizzling using options. When you disable swizzling, the SDK disables the features above:

Copied
import Sentry

SentrySDK.start { options in
    options.dsn = "https://examplePublicKey@o0.ingest.sentry.io/0"
    options.enableSwizzling = false
}

To deactivate swizzling for specific classes, you can use the option swizzleClassNameExcludes, which is available with Sentry Cocoa SDK version 8.23.0 and above. The SDK checks if the name of a class it intends to swizzle contains any class name configured using this option. For example, if you add MyUIViewController to this list, the Sentry Cocoa SDK excludes the following classes from swizzling:

  • YourApp.MyUIViewController
  • YourApp.MyUIViewControllerA
  • MyApp.MyUIViewController
Copied
import Sentry

SentrySDK.start { options in
    options.swizzleClassNameExcludes = [
      "MyUIViewController",
    ]
}
Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").