{"id":15649274,"url":"https://github.com/exphat/swiftbluetooth","last_synced_at":"2026-02-27T05:05:19.543Z","repository":{"id":197120998,"uuid":"684730054","full_name":"exPHAT/SwiftBluetooth","owner":"exPHAT","description":"📲 CoreBluetooth API's for modern Swift","archived":false,"fork":false,"pushed_at":"2025-06-05T23:33:54.000Z","size":213,"stargazers_count":57,"open_issues_count":8,"forks_count":11,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-08-13T17:01:56.759Z","etag":null,"topics":["async","bluetooth","bluetooth-low-energy","corebluetooth","ios","swift"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/exPHAT.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-08-29T18:27:58.000Z","updated_at":"2025-07-03T20:14:29.000Z","dependencies_parsed_at":"2023-12-29T16:34:51.982Z","dependency_job_id":"85bc4f34-db1d-4611-a599-38a8d026e39a","html_url":"https://github.com/exPHAT/SwiftBluetooth","commit_stats":null,"previous_names":["exphat/swiftbluetooth"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/exPHAT/SwiftBluetooth","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exPHAT%2FSwiftBluetooth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exPHAT%2FSwiftBluetooth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exPHAT%2FSwiftBluetooth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exPHAT%2FSwiftBluetooth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/exPHAT","download_url":"https://codeload.github.com/exPHAT/SwiftBluetooth/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/exPHAT%2FSwiftBluetooth/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271444338,"owners_count":24760779,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","bluetooth","bluetooth-low-energy","corebluetooth","ios","swift"],"created_at":"2024-10-03T12:29:05.131Z","updated_at":"2026-02-27T05:05:14.511Z","avatar_url":"https://github.com/exPHAT.png","language":"Swift","readme":"![SwiftBluetooth](.github/assets/logo.jpg)\n\nEasily interface with Bluetooth peripherals in new or existing projects through modern async Swift API's.\n\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FexPHAT%2FSwiftBluetooth%2Fbadge%3Ftype%3Dswift-versions)](https://swiftpackageindex.com/exPHAT/SwiftBluetooth)\n[![](https://img.shields.io/endpoint?url=https%3A%2F%2Fswiftpackageindex.com%2Fapi%2Fpackages%2FexPHAT%2FSwiftBluetooth%2Fbadge%3Ftype%3Dplatforms)](https://swiftpackageindex.com/exPHAT/SwiftBluetooth)\n\n\n## Features\n\n- [x] Parity with existing `CoreBluetooth` APIs for easy, incremental migration of existing projects\n- [x] Modern, async-await API for discovery, connection, read/write, and more\n- [x] Alternate callback-based API for codebases not using Swift Concurrency\n- [x] Subscribe to peripheral discoveries, value updates, and more through `AsyncStream`\n- [x] Easy await-ing of `CentralManager` state\n- [x] Staticly typed characteristics\n- [x] Thread safe\n- [x] Zero inherited dependencies\n- [x] Tested with included `SwiftBluetoothMock` library\n\n## Examples\n\n[API Documentation.](https://swiftpackageindex.com/exPHAT/SwiftBluetooth/1.0.0/documentation/)\n\n#### Complete example\n\nAsync API's make the entire Bluetooth lifecycle much simpler, using method names you're already familiar with from CoreBluetooth.\n\n```swift\nimport SwiftBluetooth\n\nlet central = CentralManager()\ntry await central.waitUntilReady()\n\n// Find and connect to the first available peripheral\nlet peripheral = await central.scanForPeripherals(withServices: [myService]).first!\ntry await central.connect(peripheral, timeout: connectionTimeout)\n\n// Discover services and characteristics\nlet service = try await peripheral.discoverServices([myService]).first!\nlet _ = try await peripheral.discoverCharacteristics([.someCharacteristic], for: service)\n\n// Read data directly from your characteristic\nlet value = try await peripheral.readValue(for: .someCharacteristic)\n\ncentral.cancelPeripheralConnection(peripheral)\n```\n\n#### Callbacks\n\nStock CoreBluetooth methods now also have an additional overload that takes a completionHandler for projects not using Swift Concurrency.\n\n```swift\ncentral.connect(peripheral) { result in\n  if result == .failure(let error) {\n    // Issue connecting\n    return\n  }\n\n  // Connected!\n}\n```\n\u003e Methods often now have 3 overloads. One marked `async`, one with a `completionHandler`, and the original CoreBluetooth verision. Meaning you can choose whichever is most convienient at the time.\n\n#### Stream discovered peripherals\n\nSome operations (like scanning) conform to `AsyncStream`, meaning you can use for-await-in loops to iterate over new items.\n\n```swift\nfor await peripheral in await central.scanForPeripherals() {\n  print(\"Discovered:\", peripheral.name ?? \"Unknown\")\n}\n```\n\n#### Defining characteristics\n\nCharacteristics can be staticly defined on the stock `Characteristic` type, which removes the burden of keeping track of `CBCharacteristic` instances around your app.\n\n```swift\nextension Characteristic {\n  static let someCharacteristic = Self(\"00000000-0000-0000-0000-000000000000\")\n}\n\n// Use those characteristics later on your peripheral\ntry await myPeripheral.readValue(for: .someCharacteristic)\n```\n\n\n#### Watching with callbacks\n\nPeristent tasks return a `CancellableTask` that needs to be cancelled when you're done.\n\n```swift\nlet task = central.scanForPeripherals { peripheral in\n  print(\"Discovered:\", peripheral.name ?? \"Unknown\")\n}\n\n// At some point later, cancel the task to stop scanning\ntask.cancel()\n```\n\u003e **Note**\nCalling `central.stopScan()` will also cancel any peripheral scanning tasks\n\n#### Migrate existing projects\n\nExisting projects that already use `CoreBluetooth` can immediately get started by typealiasing the stock types. Afterwards, you can adopt async API's at your own pace.\n\n```swift\nimport CoreBluetooth\nimport SwiftBluetooth // Add this\n\n// Override existing CoreBluetooth classes to use SwiftBluetooth\ntypealias CBCentralManager         = SwiftBluetooth.CentralManager\ntypealias CBCentralManagerDelegate = SwiftBluetooth.CentralManagerDelegate\ntypealias CBPeripheral             = SwiftBluetooth.Peripheral\ntypealias CBPeripheralDelegate     = SwiftBluetooth.PeripheralDelegate\n\n// Your existing code should continue to work as normal.\n// But now you have access to all the new API's!\n```\n\n\n## Install\n\n#### Xcode\n\nAdd `https://github.com/exPHAT/SwiftBluetooth.git` in the [\"Swift Package Manager\" tab.](https://developer.apple.com/documentation/xcode/adding-package-dependencies-to-your-app)\n\n\n#### Swift Package Manager\n\nAdd SwiftBluetooth as a dependency in your `Package.swift` file:\n\n```swift\nlet package = Package(\n  ...\n  dependencies: [\n    // Add the package to your dependencies\n    .package(url: \"https://github.com/exPHAT/SwiftBluetooth.git\", branch: \"master\"),\n  ],\n  ...\n  targets: [\n    // Add SwiftBluetooth as a dependency on any target you want to use it in\n    .target(name: \"MyTarget\",\n            dependencies: [.byName(name: \"SwiftBluetooth\")])\n  ]\n  ...\n)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexphat%2Fswiftbluetooth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexphat%2Fswiftbluetooth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexphat%2Fswiftbluetooth/lists"}