Skip to content

Instantly share code, notes, and snippets.

@huguesbr
Last active May 21, 2020 16:01
Show Gist options
  • Save huguesbr/0fd5eb4ad41cc78429ec941fdc5defd0 to your computer and use it in GitHub Desktop.
Save huguesbr/0fd5eb4ad41cc78429ec941fdc5defd0 to your computer and use it in GitHub Desktop.
CBUUID instantiation
extension CBUUID {
var type: UUID {
return UUID(rawValue: uuidString)!
}
enum UUID: String {
case main = "xxx"
case measure = "3749FA03-4CED-524B-33D5-F00FD858C4F2"
case alert = "3749FA05-4CED-524B-33D5-F00FD858C4F2"
var cbuuid: CBUUID { return CBUUID(string: self.rawValue) }
}
static func common(_ type: UUID) -> CBUUID {
return type.cbuuid
}
}
// usage
peripheral.discoverServices([.common(.main)])
print(CBUUID(string: "xxx").type == .alert)
import Foundation
import CoreBluetooth
struct CBDevice {
}
extension CBUUID {
static var device: CBDevice { return CBDevice() }
}
/*
extension CBUUID: ExpressibleByStringLiteral {
typealias StringLiteralType = String
init(stringLiteral value: String) {
self = CBUUID(string: value)
}
init(unicodeScalarLiteral value: String) {
self = CBUUID(string: value)
}
init(extendedGraphemeClusterLiteral value: String) {
self = CBUUID(string: value)
}
}
*/
extension CBDevice {
var uuid: UUID.Type { return UUID.self }
enum UUID: String {
case main = "3749FA00-4CED-524B-33D5-F00FD858C4F2"
case info = "3749FA01-4CED-524B-33D5-F00FD858C4F2"
case config = "3749FA02-4CED-524B-33D5-F00FD858C4F2"
case measure = "3749FA03-4CED-524B-33D5-F00FD858C4F2"
case protection = "3749FA04-4CED-524B-33D5-F00FD858C4F2"
case alert = "3749FA05-4CED-524B-33D5-F00FD858C4F2"
var cbuuid: CBUUID { return CBUUID(string: self.rawValue) }
}
}
extension CBUUID {
var type: CBDevice.UUID? {
return CBDevice.UUID(rawValue: uuidString)
}
}
let service = CBMutableService(type: CBUUID.device.uuid.alert.cbuuid, primary: true)
service.uuid.type
CBUUID.device.uuid.alert
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment