---
title: "setBadgeCount(_:withCompletionHandler:)"
framework: usernotifications
role: symbol
role_heading: Instance Method
path: "usernotifications/unusernotificationcenter/setbadgecount(_:withcompletionhandler:)"
---

# setBadgeCount(_:withCompletionHandler:)

Updates the badge count for your app’s icon.

## Declaration

```swift
func setBadgeCount(_ newBadgeCount: Int, withCompletionHandler completionHandler: (@Sendable ((any Error)?) -> Void)? = nil)
```

```swift
func setBadgeCount(_ newBadgeCount: Int) async throws
```

## Parameters

- `newBadgeCount`: The new value to display.
- `completionHandler`: The handler to execute after the update finishes. If the update fails, the system provides an error that contains additional information about the failure.

## Discussion

Discussion important: You can call this method from synchronous code using a completion handler, as shown on this page, or you can call it as an asynchronous method that has the following declaration: func setBadgeCount(_ newBadgeCount: Int) async throws For information about concurrency and asynchronous code in Swift, see Calling Objective-C APIs Asynchronously. Here’s an example that sets the badge count to a specific number. let center = UNUserNotificationCenter.current() do {      // Set the badge count to 3.      try await center.setBadgeCount(3) } catch {      // Handle any errors. }

## See Also

### Managing the notification center

- [current()](usernotifications/unusernotificationcenter/current().md)
- [getNotificationSettings(completionHandler:)](usernotifications/unusernotificationcenter/getnotificationsettings(completionhandler:).md)
