{"abstract":[{"text":"Updates the badge count for your app’s icon.","type":"text"}],"hierarchy":{"paths":[["doc:\/\/com.apple.documentation\/documentation\/technologies","doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications","doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter"]]},"identifier":{"interfaceLanguage":"swift","url":"doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter\/setBadgeCount(_:withCompletionHandler:)"},"kind":"symbol","legalNotices":{"copyright":"Copyright &copy; 2026 Apple Inc. All rights reserved.","privacyPolicy":"https:\/\/www.apple.com\/privacy\/privacy-policy","termsOfUse":"https:\/\/www.apple.com\/legal\/internet-services\/terms\/site.html"},"metadata":{"availableLanguages":["de-DE","en-US","es-419","fr-FR","it-IT","ja-JP","ko-KR","pt-BR","zh-CN"],"externalID":"c:objc(cs)UNUserNotificationCenter(im)setBadgeCount:withCompletionHandler:","fragments":[{"kind":"keyword","text":"func"},{"kind":"text","text":" "},{"kind":"identifier","text":"setBadgeCount"},{"kind":"text","text":"("},{"kind":"typeIdentifier","preciseIdentifier":"s:Si","text":"Int"},{"kind":"text","text":", "},{"kind":"externalParam","text":"withCompletionHandler"},{"kind":"text","text":": (((any "},{"kind":"typeIdentifier","preciseIdentifier":"s:s5ErrorP","text":"Error"},{"kind":"text","text":")?) -> "},{"kind":"typeIdentifier","preciseIdentifier":"s:s4Voida","text":"Void"},{"kind":"text","text":")?)"}],"modules":[{"name":"User Notifications"}],"navigatorTitle":[{"kind":"text","text":"- "},{"kind":"identifier","text":"setBadgeCount:withCompletionHandler:"}],"platforms":[{"introducedAt":"16.0","name":"iOS"},{"introducedAt":"16.0","name":"iPadOS"},{"introducedAt":"16.0","name":"Mac Catalyst"},{"introducedAt":"13.0","name":"macOS"},{"introducedAt":"16.0","name":"tvOS"},{"introducedAt":"1.0","name":"visionOS"}],"role":"symbol","roleHeading":"Instance Method","symbolKind":"method","title":"setBadgeCount(_:withCompletionHandler:)"},"primaryContentSections":[{"declarations":[{"languages":["swift"],"platforms":["iOS","iPadOS","Mac Catalyst","macOS","tvOS","visionOS"],"tokens":[{"kind":"keyword","text":"func"},{"kind":"text","text":" "},{"kind":"identifier","text":"setBadgeCount"},{"kind":"text","text":"("},{"kind":"externalParam","text":"_"},{"kind":"text","text":" "},{"kind":"internalParam","text":"newBadgeCount"},{"kind":"text","text":": "},{"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/Int","kind":"typeIdentifier","preciseIdentifier":"s:Si","text":"Int"},{"kind":"text","text":", "},{"kind":"externalParam","text":"withCompletionHandler"},{"kind":"text","text":" "},{"kind":"internalParam","text":"completionHandler"},{"kind":"text","text":": ("},{"kind":"attribute","text":"@Sendable"},{"kind":"text","text":" ((any "},{"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/Error","kind":"typeIdentifier","preciseIdentifier":"s:s5ErrorP","text":"Error"},{"kind":"text","text":")?) -> "},{"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/Void","kind":"typeIdentifier","preciseIdentifier":"s:s4Voida","text":"Void"},{"kind":"text","text":")? = nil)"}]},{"languages":["swift"],"platforms":["iOS","iPadOS","Mac Catalyst","macOS","tvOS","visionOS"],"tokens":[{"kind":"keyword","text":"func"},{"kind":"text","text":" "},{"kind":"identifier","text":"setBadgeCount"},{"kind":"text","text":"("},{"kind":"externalParam","text":"_"},{"kind":"text","text":" "},{"kind":"internalParam","text":"newBadgeCount"},{"kind":"text","text":": "},{"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/Int","kind":"typeIdentifier","preciseIdentifier":"s:Si","text":"Int"},{"kind":"text","text":") "},{"kind":"keyword","text":"async"},{"kind":"text","text":" "},{"kind":"keyword","text":"throws"}]}],"kind":"declarations"},{"kind":"parameters","parameters":[{"content":[{"inlineContent":[{"text":"The new value to display.","type":"text"}],"type":"paragraph"}],"name":"newBadgeCount"},{"content":[{"inlineContent":[{"text":"The handler to execute after the update finishes. If the update fails, the system provides an error that contains additional information about the failure.","type":"text"}],"type":"paragraph"}],"name":"completionHandler"}]},{"content":[{"anchor":"Discussion","level":2,"text":"Discussion","type":"heading"},{"content":[{"inlineContent":[{"text":"","type":"text"},{"text":" ","type":"text"},{"text":"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:","type":"text"}],"type":"paragraph"},{"code":["func setBadgeCount(_ newBadgeCount: Int) async throws"],"copyToClipboard":true,"lineAnnotations":[],"showLineNumbers":false,"syntax":"swift","type":"codeListing","wrap":0},{"inlineContent":[{"text":"For information about concurrency and asynchronous code in Swift, see ","type":"text"},{"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/calling-objective-c-apis-asynchronously","isActive":true,"type":"reference"},{"text":".","type":"text"}],"type":"paragraph"}],"name":"Important","style":"important","type":"aside"},{"inlineContent":[{"text":"Here’s an example that sets the badge count to a specific number.","type":"text"}],"type":"paragraph"},{"code":["let center = UNUserNotificationCenter.current()","do {","     \/\/ Set the badge count to 3.","     try await center.setBadgeCount(3)","} catch {","     \/\/ Handle any errors.","}"],"copyToClipboard":true,"lineAnnotations":[],"showLineNumbers":false,"syntax":"swift","type":"codeListing","wrap":0}],"kind":"content"}],"schemaVersion":{"major":0,"minor":3,"patch":0},"sections":[],"seeAlsoSections":[{"anchor":"Managing-the-notification-center","generated":true,"identifiers":["doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter\/current()","doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter\/getNotificationSettings(completionHandler:)"],"title":"Managing the notification center"}],"variants":[{"paths":["\/documentation\/usernotifications\/unusernotificationcenter\/setbadgecount(_:withcompletionhandler:)"],"traits":[{"interfaceLanguage":"swift"}]},{"paths":["\/documentation\/usernotifications\/unusernotificationcenter\/setbadgecount(_:withcompletionhandler:)"],"traits":[{"interfaceLanguage":"occ"}]}],"references":{"UserNotifications-PageImage-card.png":{"alt":"[A notification interface displayed on the lock screen of an iOS device.]","identifier":"UserNotifications-PageImage-card.png","type":"image","variants":[{"traits":["2x","light"],"url":"\/images\/com.apple.usernotifications\/UserNotifications-PageImage-card@2x.png"},{"traits":["2x","dark"],"url":"\/images\/com.apple.usernotifications\/UserNotifications-PageImage-card~dark@2x.png"}]},"doc://com.apple.documentation/documentation/Swift/Error":{"abstract":[{"text":"A type representing an error value that can be thrown.","type":"text"}],"fragments":[{"kind":"keyword","text":"protocol"},{"kind":"text","text":" "},{"kind":"identifier","text":"Error"}],"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/Error","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"Error"}],"role":"symbol","title":"Error","type":"topic","url":"\/documentation\/swift\/error"},"doc://com.apple.documentation/documentation/Swift/Int":{"abstract":[{"text":"A signed integer value type.","type":"text"}],"fragments":[{"kind":"keyword","text":"struct"},{"kind":"text","text":" "},{"kind":"identifier","text":"Int"}],"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/Int","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"Int"}],"role":"symbol","title":"Int","type":"topic","url":"\/documentation\/swift\/int"},"doc://com.apple.documentation/documentation/Swift/Void":{"abstract":[{"text":"The return type of functions that don’t explicitly specify a return type,","type":"text"},{"text":" ","type":"text"},{"text":"that is, an empty tuple ","type":"text"},{"code":"()","type":"codeVoice"},{"text":".","type":"text"}],"fragments":[{"kind":"keyword","text":"typealias"},{"kind":"text","text":" "},{"kind":"identifier","text":"Void"}],"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/Void","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"Void"}],"role":"symbol","title":"Void","type":"topic","url":"\/documentation\/swift\/void"},"doc://com.apple.documentation/documentation/Swift/calling-objective-c-apis-asynchronously":{"abstract":[{"text":"Learn how functions and methods that take a completion handler are converted to Swift","type":"text"},{"text":" ","type":"text"},{"text":"asynchronous functions.","type":"text"}],"identifier":"doc:\/\/com.apple.documentation\/documentation\/Swift\/calling-objective-c-apis-asynchronously","kind":"article","role":"article","title":"Calling Objective-C APIs Asynchronously","type":"topic","url":"\/documentation\/swift\/calling-objective-c-apis-asynchronously"},"doc://com.apple.documentation/documentation/technologies":{"abstract":[],"identifier":"doc:\/\/com.apple.documentation\/documentation\/technologies","kind":"technologies","role":"overview","title":"Technologies","type":"topic","url":"\/documentation\/technologies"},"doc://com.apple.usernotifications/documentation/UserNotifications":{"abstract":[{"text":"Push user-facing notifications to the user’s device from a server, or generate them locally from your app.","type":"text"}],"identifier":"doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications","images":[{"identifier":"UserNotifications-PageImage-card.png","type":"card"}],"kind":"symbol","navigatorTitle":[{"kind":"text","text":"User Notifications"}],"role":"collection","title":"User Notifications","type":"topic","url":"\/documentation\/usernotifications"},"doc://com.apple.usernotifications/documentation/UserNotifications/UNUserNotificationCenter":{"abstract":[{"text":"The central object for managing notification-related activities for your app or app extension.","type":"text"}],"fragments":[{"kind":"keyword","text":"class"},{"kind":"text","text":" "},{"kind":"identifier","text":"UNUserNotificationCenter"}],"identifier":"doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter","kind":"symbol","navigatorTitle":[{"kind":"identifier","text":"UNUserNotificationCenter"}],"role":"symbol","title":"UNUserNotificationCenter","type":"topic","url":"\/documentation\/usernotifications\/unusernotificationcenter"},"doc://com.apple.usernotifications/documentation/UserNotifications/UNUserNotificationCenter/current()":{"abstract":[{"text":"Returns your app’s notification center.","type":"text"}],"fragments":[{"kind":"keyword","text":"class"},{"kind":"text","text":" "},{"kind":"keyword","text":"func"},{"kind":"text","text":" "},{"kind":"identifier","text":"current"},{"kind":"text","text":"() -> "},{"kind":"typeIdentifier","preciseIdentifier":"c:objc(cs)UNUserNotificationCenter","text":"UNUserNotificationCenter"}],"identifier":"doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter\/current()","kind":"symbol","navigatorTitle":[{"kind":"text","text":"+ "},{"kind":"identifier","text":"currentNotificationCenter"}],"role":"symbol","title":"current()","type":"topic","url":"\/documentation\/usernotifications\/unusernotificationcenter\/current()"},"doc://com.apple.usernotifications/documentation/UserNotifications/UNUserNotificationCenter/getNotificationSettings(completionHandler:)":{"abstract":[{"text":"Retrieves the authorization and feature-related settings for your app.","type":"text"}],"fragments":[{"kind":"keyword","text":"func"},{"kind":"text","text":" "},{"kind":"identifier","text":"getNotificationSettings"},{"kind":"text","text":"("},{"kind":"externalParam","text":"completionHandler"},{"kind":"text","text":": ("},{"kind":"typeIdentifier","preciseIdentifier":"c:objc(cs)UNNotificationSettings","text":"UNNotificationSettings"},{"kind":"text","text":") -> "},{"kind":"typeIdentifier","preciseIdentifier":"s:s4Voida","text":"Void"},{"kind":"text","text":")"}],"identifier":"doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter\/getNotificationSettings(completionHandler:)","kind":"symbol","navigatorTitle":[{"kind":"text","text":"- "},{"kind":"identifier","text":"getNotificationSettingsWithCompletionHandler:"}],"role":"symbol","title":"getNotificationSettings(completionHandler:)","type":"topic","url":"\/documentation\/usernotifications\/unusernotificationcenter\/getnotificationsettings(completionhandler:)"},"doc://com.apple.usernotifications/documentation/UserNotifications/UNUserNotificationCenter/setBadgeCount(_:withCompletionHandler:)":{"abstract":[{"text":"Updates the badge count for your app’s icon.","type":"text"}],"fragments":[{"kind":"keyword","text":"func"},{"kind":"text","text":" "},{"kind":"identifier","text":"setBadgeCount"},{"kind":"text","text":"("},{"kind":"typeIdentifier","preciseIdentifier":"s:Si","text":"Int"},{"kind":"text","text":", "},{"kind":"externalParam","text":"withCompletionHandler"},{"kind":"text","text":": (((any "},{"kind":"typeIdentifier","preciseIdentifier":"s:s5ErrorP","text":"Error"},{"kind":"text","text":")?) -> "},{"kind":"typeIdentifier","preciseIdentifier":"s:s4Voida","text":"Void"},{"kind":"text","text":")?)"}],"identifier":"doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter\/setBadgeCount(_:withCompletionHandler:)","kind":"symbol","navigatorTitle":[{"kind":"text","text":"- "},{"kind":"identifier","text":"setBadgeCount:withCompletionHandler:"}],"role":"symbol","title":"setBadgeCount(_:withCompletionHandler:)","type":"topic","url":"\/documentation\/usernotifications\/unusernotificationcenter\/setbadgecount(_:withcompletionhandler:)"}},"variantOverrides":[{"patch":[{"op":"replace","path":"\/identifier\/interfaceLanguage","value":"occ"},{"op":"replace","path":"\/metadata\/platforms","value":[{"introducedAt":"16.0","name":"iOS"},{"introducedAt":"16.0","name":"iPadOS"},{"introducedAt":"16.0","name":"Mac Catalyst"},{"introducedAt":"13.0","name":"macOS"},{"introducedAt":"16.0","name":"tvOS"},{"introducedAt":"1.0","name":"visionOS"}]},{"op":"replace","path":"\/metadata\/roleHeading","value":"Instance Method"},{"op":"replace","path":"\/metadata\/title","value":"setBadgeCount:withCompletionHandler:"},{"op":"replace","path":"\/metadata\/symbolKind","value":"method"},{"op":"replace","path":"\/metadata\/fragments","value":[{"kind":"text","text":"- "},{"kind":"identifier","text":"setBadgeCount:withCompletionHandler:"}]},{"op":"replace","path":"\/hierarchy","value":{"paths":[["doc:\/\/com.apple.documentation\/documentation\/technologies","doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications","doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter"]]}},{"op":"add","path":"\/topicSections","value":null},{"op":"add","path":"\/relationshipsSections","value":null},{"op":"replace","path":"\/seeAlsoSections","value":[{"anchor":"Managing-the-notification-center","generated":true,"identifiers":["doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter\/current()","doc:\/\/com.apple.usernotifications\/documentation\/UserNotifications\/UNUserNotificationCenter\/getNotificationSettings(completionHandler:)"],"title":"Managing the notification center"}]},{"op":"replace","path":"\/primaryContentSections\/0","value":{"declarations":[{"languages":["occ"],"platforms":["iOS","iPadOS","Mac Catalyst","macOS","tvOS","visionOS","watchOS"],"tokens":[{"kind":"text","text":"- ("},{"kind":"typeIdentifier","preciseIdentifier":"c:v","text":"void"},{"kind":"text","text":") "},{"kind":"identifier","text":"setBadgeCount:"},{"kind":"text","text":"("},{"kind":"typeIdentifier","preciseIdentifier":"c:@T@NSInteger","text":"NSInteger"},{"kind":"text","text":") "},{"kind":"internalParam","text":"newBadgeCount"},{"kind":"text","text":" "},{"kind":"identifier","text":"withCompletionHandler:"},{"kind":"text","text":"("},{"kind":"typeIdentifier","preciseIdentifier":"c:v","text":"void"},{"kind":"text","text":" (^)("},{"kind":"typeIdentifier","preciseIdentifier":"c:objc(cs)NSError","text":"NSError"},{"kind":"text","text":" *"},{"kind":"internalParam","text":"error"},{"kind":"text","text":")) "},{"kind":"internalParam","text":"completionHandler"},{"kind":"text","text":";"}]}],"kind":"declarations"}},{"op":"replace","path":"\/primaryContentSections\/1","value":{"kind":"parameters","parameters":[{"content":[{"inlineContent":[{"text":"The new value to display.","type":"text"}],"type":"paragraph"}],"name":"newBadgeCount"},{"content":[{"inlineContent":[{"text":"The handler to execute after the update finishes. If the update fails, the system provides an error that contains additional information about the failure.","type":"text"}],"type":"paragraph"}],"name":"completionHandler"}]}},{"op":"replace","path":"\/references\/doc:~1~1com.apple.usernotifications~1documentation~1UserNotifications~1UNUserNotificationCenter\/title","value":"UNUserNotificationCenter"},{"op":"replace","path":"\/references\/doc:~1~1com.apple.usernotifications~1documentation~1UserNotifications~1UNUserNotificationCenter\/fragments","value":[{"kind":"identifier","text":"UNUserNotificationCenter"}]},{"op":"replace","path":"\/references\/doc:~1~1com.apple.usernotifications~1documentation~1UserNotifications~1UNUserNotificationCenter\/navigatorTitle","value":[{"kind":"identifier","text":"UNUserNotificationCenter"}]},{"op":"replace","path":"\/references\/doc:~1~1com.apple.usernotifications~1documentation~1UserNotifications~1UNUserNotificationCenter~1current()\/title","value":"currentNotificationCenter"},{"op":"replace","path":"\/references\/doc:~1~1com.apple.usernotifications~1documentation~1UserNotifications~1UNUserNotificationCenter~1current()\/fragments","value":[{"kind":"text","text":"+ "},{"kind":"identifier","text":"currentNotificationCenter"}]},{"op":"replace","path":"\/references\/doc:~1~1com.apple.usernotifications~1documentation~1UserNotifications~1UNUserNotificationCenter~1getNotificationSettings(completionHandler:)\/title","value":"getNotificationSettingsWithCompletionHandler:"},{"op":"replace","path":"\/references\/doc:~1~1com.apple.usernotifications~1documentation~1UserNotifications~1UNUserNotificationCenter~1getNotificationSettings(completionHandler:)\/fragments","value":[{"kind":"text","text":"- "},{"kind":"identifier","text":"getNotificationSettingsWithCompletionHandler:"}]},{"op":"replace","path":"\/references\/doc:~1~1com.apple.usernotifications~1documentation~1UserNotifications~1UNUserNotificationCenter~1setBadgeCount(_:withCompletionHandler:)\/title","value":"setBadgeCount:withCompletionHandler:"},{"op":"replace","path":"\/references\/doc:~1~1com.apple.usernotifications~1documentation~1UserNotifications~1UNUserNotificationCenter~1setBadgeCount(_:withCompletionHandler:)\/fragments","value":[{"kind":"text","text":"- "},{"kind":"identifier","text":"setBadgeCount:withCompletionHandler:"}]}],"traits":[{"interfaceLanguage":"occ"}]}]}