Skip to content

Commit

Permalink
Added UInt128.init(uuid: UUID)
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Dec 4, 2017
1 parent f111176 commit d3b38a6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
6 changes: 2 additions & 4 deletions Sources/BluetoothUUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ extension BluetoothUUID: RawRepresentable {
guard let uuid = UUID(uuidString: rawValue)
else { return nil }

let bigEndian = UInt128(bytes: uuid.uuid)

self = BluetoothUUID.init(bigEndian: .bit128(bigEndian))
self = .bit128(UInt128(uuid: uuid))

default:

Expand Down Expand Up @@ -289,7 +287,7 @@ public extension BluetoothUUID {
/// Initialize from a `Foundation.UUID`.
public init(uuid: UUID) {

self.init(bigEndian: BluetoothUUID(data: uuid.data)!)
self.init(bigEndian: .bit128(UInt128(uuid: uuid)))
}

/// Bluetooth Base UUID (big endian)
Expand Down
13 changes: 12 additions & 1 deletion Sources/UInt128.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,18 @@ public extension UInt128 {

// MARK: - NSUUID

public extension UUID {
public extension UInt128 {

public init(uuid: Foundation.UUID) {

/// UUID is always big endian
let bigEndian = UInt128(bytes: uuid.uuid)

self.init(bigEndian: bigEndian)
}
}

public extension Foundation.UUID {

public init(_ value: UInt128) {

Expand Down

0 comments on commit d3b38a6

Please sign in to comment.