Skip to content

nordicsemi/IOS-BLE-Library

Repository files navigation

iOS-BLE-Library

Platforms License Release GitHub stars GitHub forks GitHub contributors

This library is a wrapper around the CoreBluetooth framework which provides a modern async API based on Combine.

Library Versions

The package ships two products, and consumers pick the one that fits their needs:

  • iOS-BLE-Library — links real CoreBluetooth. For production apps.
  • iOS-BLE-Library-Mock — links CoreBluetoothMock. The public API is identical (a top-level Alias.swift re-exports CB* names for the underlying CBM* types), so code written for iOS-BLE-Library recompiles unchanged against iOS-BLE-Library-Mock for unit testing.

Architecture

Both products are built from a single source tree at Sources/iOS-BLE-Library/. The Mock target's compilation unit is produced at build time by the MockGenerator SwiftPM build plugin — there are no Python scripts, no committed duplicates, no manual sync step.

At the handful of sites where the two products diverge (mostly imports, plus a couple of init-time branches), the source uses native Swift conditional compilation:

#if MOCK_TRANSPORT
import CoreBluetoothMock
#else
import CoreBluetooth
#endif

The Mock target sets swiftSettings: [.define("MOCK_TRANSPORT")]; the native target leaves the flag undefined. The compiler picks the right branch per build.

For contributors

  1. Edit files only in Sources/iOS-BLE-Library/. Do not edit anything under Sources/iOS-BLE-Library-Mock/ (other than Alias.swift and Documentation.docc/, which are static).
  2. For code that needs to behave differently in the Mock build, wrap it in #if MOCK_TRANSPORT … #else … #endif.
  3. Run swift build — the plugin re-generates the Mock target's sources automatically.

That's the whole workflow. No code_gen step, no marker DSL.

Installation

Swift Package Manager

Add the package to your Package.swift dependencies and pick the product you need:

let package = Package(
    // ...
    dependencies: [
        .package(url: "https://github.com/nordicsemi/IOS-BLE-Library.git", from: "1.0.0"),
    ],
    targets: [
        .target(
            name: "MyApp",
            dependencies: [
                // Production: links real CoreBluetooth
                .product(name: "iOS-BLE-Library", package: "IOS-BLE-Library")
            ]
        ),
        .testTarget(
            name: "MyAppTests",
            dependencies: [
                "MyApp",
                // Testing: links CoreBluetoothMock
                .product(name: "iOS-BLE-Library-Mock", package: "IOS-BLE-Library")
            ]
        ),
    ]
)

Documentation & Examples

Please check the Documentation Page to start using the library.

Also you can check iOS-nRF-Toolbox to find more examples.

Special Thanks

Please consider backing this project by using the following GitHub Sponsor button.

We want to thank all of our contributors for all of their additions and improvements to this project. With special mention to one in particular: Nick!

About

The Bluetooth LE library for iOS and Mac. 100% Swift.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages