{"id":15050732,"url":"https://github.com/fraune/cbsafekit","last_synced_at":"2026-01-02T01:29:32.294Z","repository":{"id":212751316,"uuid":"732228606","full_name":"fraune/CBSafeKit","owner":"fraune","description":"Swift helper for CoreBluetooth that makes instantiating dangerous types safer and easier","archived":false,"fork":false,"pushed_at":"2024-01-03T06:16:57.000Z","size":26,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-12T17:41:17.583Z","etag":null,"topics":["corebluetooth","foss","objective-c","swift","xcode"],"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/fraune.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-12-16T01:37:58.000Z","updated_at":"2024-03-31T04:52:18.000Z","dependencies_parsed_at":"2024-01-03T00:21:46.054Z","dependency_job_id":"c5b9a4a5-ba22-40a4-a978-15f3f4ce80ba","html_url":"https://github.com/fraune/CBSafeKit","commit_stats":null,"previous_names":["fraune/swift-cbuuid-kit","fraune/cbsafekit"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraune%2FCBSafeKit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraune%2FCBSafeKit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraune%2FCBSafeKit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fraune%2FCBSafeKit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fraune","download_url":"https://codeload.github.com/fraune/CBSafeKit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225406554,"owners_count":17469551,"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","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":["corebluetooth","foss","objective-c","swift","xcode"],"created_at":"2024-09-24T21:29:08.522Z","updated_at":"2026-01-02T01:29:32.258Z","avatar_url":"https://github.com/fraune.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CBSafeKit\n\n[![Version](https://img.shields.io/badge/version-1.1.0-blue)](https://github.com/fraune/CBSafeKit/releases/tag/v1.1.0)\n[![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/fraune/swift-cbuuid-kit/blob/main/LICENSE)\n\nCBSafeKit is a lightweight helper package, to help Swift programmers safely instantiate various CoreBluetooth objects.\n\n## Contents\n1. [Contents](#contents)\n1. [Introduction](#introduction)\n1. [Getting Started](#getting-started)\n1. [Usage](#usage)\n1. [API Reference](#api-reference)\n1. [CoreBluetooth Undocumentation](#corebluetooth-undocumentation)\n1. [Contributing](#contributing)\n1. [License](#license)\n\n## Introduction\n\nInstantiating some CoreBluetooth objects can cause your program to raise `NSInternalInconsistencyException`s, which cannot be handled in a Swift do-catch. Unfortunately, there is very limited documentation for what is/isn't valid input for these types. As such, you might be tempted to write a lot of code, attempting to validate inputs that _might_ be valid.\n\nThis package solves that problem, by using Objective-C to bridge dangerous instantiations into safe Swift interfaces. Using this library, you are free to attempt all the invalid instantiations you like, and can easily handle the results in a \"Swift\" way.\n\n## Getting Started\n\n### Swift Package Manager (SPM)\n\nAdd this repository as a SPM project/package dependency in Xcode:\n\n```\nhttps://github.com/fraune/CBSafeKit\n```\n\n## Usage\n\nAfter importing the package, you can use [one of the helpers](#api-reference) to safely create an optional. Use guard-let or if-let to safely unwrap the optional.\n\n### Example usage of getting a concrete CBUUID safely:\n\n```swift\nimport CoreBluetooth\nimport CBSafeKit\n\nfunc doSomething() {\n    let input = \"Invalid\"\n\n    guard let cbuuid: CBUUID = SafeCBUUID(string: input) else {\n        print(\"Unable to create CBUUID with: \\(input)\")\n        return\n    }\n\n    print(\"Safe to proceed\")\n    doSomethingElse(cbuuid)\n}\n```\n\n## API Reference\n\n### SafeCBUUID(string: String)\n\n* Safe alternative to `CBUUID(string: String)`\n* Returns `CBUUID?`\n* Does not throw\n\n### SafeCBMutableService(type: CBUUID, primary: Bool)\n\n* Safe alternative to `CBMutableService(type: CBUUID, primary: Bool)`\n* Returns `CBMutableService?`\n* Does not throw\n\n## CoreBluetooth Undocumentation\n\n_\"undocumentation\" = important notes not officially documented by Apple_\n\n### [CBUUID.init(string:)](https://developer.apple.com/documentation/corebluetooth/cbuuid/1519025-init)\n\nThe following inputs will cause this method to throw an `NSInternalInconsistencyException`:\n* If `string` length is 4 or 8:\n    * It is not entirely hexadecimal (case insensitive)\n* Or, if `string` length is 36:\n    * It does not contain dashes at indices: 8, 13, 18, and 23 (i.e. UUID format)\n    * All other characters are not hexadecimal (case insensitive)\n* Else, the error will be thrown\n\n### [CBMutableService.init(type:primary:)](https://developer.apple.com/documentation/corebluetooth/cbmutableservice/1434330-init)\n\nThe following inputs will cause this method to throw an `NSInternalInconsistencyException`:\n* A valid CBUUID with a `data.length` that is not 2 or 16\n    * Specifically, a valid CBUUID with a byte-length of 4 (8 hex characters) will cause this constructor to throw the error\n        * e.g. `CBUUID(string: \"ABCD1234\")`\n\n### [CBMutableCharacteristic.init(type:properties:value:permissions:)](https://developer.apple.com/documentation/corebluetooth/cbmutablecharacteristic/1519073-init)\n\nYou might notice this package provides a safe constructor for `CBMutableService`, but not for `CBMutableCharacteristic`. Interestingly, this is not necessary: while a valid CBUUID with a byte-length of 4 (8 hex characters) is not a valid parameter for `CBMutableService`, it _is_ a valid parameter for `CBMutableCharacteristic`!\n\n## Contributing\n\nThis package is simple, but contributer-friendly. I don't have a template or style guide right now, so if you would like to contribute, reach out.\n\n### Scope\n\nKeep the scope of this package limited to CoreBluetooth \"safety\" helpers.\n\n### Documentation\n\nIf you can add to or refine any of the documentation, please open a PR with an update and unit test.\n\n## License\n\nhttps://github.com/fraune/swift-cbuuid-kit/blob/main/LICENSE\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffraune%2Fcbsafekit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffraune%2Fcbsafekit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffraune%2Fcbsafekit/lists"}