Upgrade from 4.x to 5.x

Learn about migrating from Sentry Cocoa SDK 4.x to 5.x.

The samples below illustrate how the SDK works:

Example in 4.x:

Copied
do {
    Client.shared = try Client(dsn: "___PUBLIC_DSN___")
    try Client.shared?.startCrashHandler()
} catch let error {
    print("\(error)")
}

Example in 5.x:

Copied
SentrySDK.start(options: [
    "dsn": "___PUBLIC_DSN___",
    "debug": true
])

Example in 4.x:`

Copied
Client.shared?.breadcrumbs.add(Breadcrumb(level: .info, category: "test"))

Example in 5.x:

Copied
SentrySDK.addBreadcrumb(Breadcrumb(level: .info, category: "test"))

Example in 4.x:

Copied
let event = Event(level: .debug)
event.message = "Test Message"
event.environment = "staging"
event.extra = ["ios": true]
Client.shared?.send(event: event)

Example in 5.x:

Copied
SentrySDK.capture(message: "Test Message") { (scope) in
    scope.setEnvironment("staging")
    scope.setExtras(["ios": true])
    let u = Sentry.User(userId: "1")
    u.email = "tony@example.com"
    scope.setUser(u)
}

Example in 4.x:

Copied
let u = User(userId: "1")
u.email = "tony@example.com"
Client.shared?.user = user

Example in 5.x:

Copied
let u = Sentry.User(userId: "1")
u.email = "tony@example.com"
SentrySDK.setUser(u)
Was this helpful?
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").