Skip to content

Commit

Permalink
fixed GATTDatabase.remove()
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Apr 22, 2016
1 parent 25145d5 commit 38e3d54
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Sources/BluetoothLinux/GATTDatabase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct GATTDatabase {

// MARK: - Methods

public mutating func add(service: Service) -> Int {
public mutating func add(service: Service) -> UInt16 {

let serviceAttribute = Attribute(service: service, handle: newHandle())

Expand All @@ -63,7 +63,7 @@ public struct GATTDatabase {

attributeGroups.append(group)

return attributeGroups.endIndex
return serviceAttribute.handle
}

/// Clear the database.
Expand All @@ -73,9 +73,12 @@ public struct GATTDatabase {
}

/// Remove the Service at the specified index.
public mutating func remove(service index: Int) {
public mutating func remove(service handle: UInt16) {

attributeGroups.remove(at: index)
guard let serviceIndex = attributeGroups.index(where: { $0.service.handle == handle })
else { fatalError("Service with handle \(handle) doesnt exist") }

attributeGroups.remove(at: serviceIndex)
}

/// Write the value to attribute specified by the handle.
Expand Down

0 comments on commit 38e3d54

Please sign in to comment.