Skip to content

Commit

Permalink
Merge branch 'swift-3'
Browse files Browse the repository at this point in the history
  • Loading branch information
rhummelmose committed Oct 21, 2016
2 parents 882879d + c0baddd commit b502d0a
Show file tree
Hide file tree
Showing 19 changed files with 245 additions and 203 deletions.
Binary file added .DS_Store
Binary file not shown.
Binary file added Source/.DS_Store
Binary file not shown.
62 changes: 38 additions & 24 deletions Source/BKAvailability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,26 @@ public enum BKAvailability: Equatable {
case unavailable(cause: BKUnavailabilityCause)

@available(iOS 10.0, *)
internal init(centralManagerState: CBManagerState) {
switch centralManagerState {
internal init(centralState: CBManagerState) {
switch centralState {
case .poweredOn: self = .available
default: self = .unavailable(cause: BKUnavailabilityCause(centralManagerState: centralManagerState))
default: self = .unavailable(cause: BKUnavailabilityCause(centralState: centralState))
}
}

@available(iOS 10.0, *)
internal init(peripheralManagerState: CBManagerState) {
internal init(centralManagerState: CBCentralManagerState){
switch centralManagerState {
case .poweredOn: self = .available
default: self = .unavailable(cause: BKUnavailabilityCause(centralManagerState: centralManagerState))
}
}

internal init(peripheralManagerState: CBPeripheralManagerState){
switch peripheralManagerState {
case .poweredOn: self = .available
default: self = .unavailable(cause: BKUnavailabilityCause(peripheralManagerState: peripheralManagerState))
case .poweredOn: self = .available
default: self = .unavailable(cause: BKUnavailabilityCause(peripheralManagerState: peripheralManagerState))
}
}

}

/**
Expand All @@ -82,28 +87,37 @@ public enum BKUnavailabilityCause: NilLiteralConvertible {
case poweredOff

public init(nilLiteral: Void) {
self = any
self = .any
}

@available(iOS 10.0, *)
internal init(centralManagerState: CBManagerState) {
switch centralManagerState {
case .poweredOff: self = poweredOff
case .resetting: self = resetting
case .unauthorized: self = unauthorized
case .unsupported: self = unsupported
internal init(centralState: CBManagerState) {
switch centralState {
case .poweredOff: self = .poweredOff
case .resetting: self = .resetting
case .unauthorized: self = .unauthorized
case .unsupported: self = .unsupported
default: self = nil
}
}

@available(iOS 10.0, *)
internal init(peripheralManagerState: CBManagerState) {
internal init(centralManagerState: CBCentralManagerState) {
switch centralManagerState {
case .poweredOff: self = .poweredOff
case .resetting: self = .resetting
case .unauthorized: self = .unauthorized
case .unsupported: self = .unsupported
default: self = nil
}
}

internal init(peripheralManagerState: CBPeripheralManagerState) {
switch peripheralManagerState {
case .poweredOff: self = poweredOff
case .resetting: self = resetting
case .unauthorized: self = unauthorized
case .unsupported: self = unsupported
default: self = nil
case .poweredOff: self = .poweredOff
case .resetting: self = .resetting
case .unauthorized: self = .unauthorized
case .unsupported: self = .unsupported
default: self = nil
}
}

Expand Down Expand Up @@ -135,7 +149,7 @@ public extension BKAvailabilityObservable {
- parameter availabilityObserver: The availability observer to add.
*/
func addAvailabilityObserver(_ availabilityObserver: BKAvailabilityObserver) {
if !availabilityObservers.contains({ $0.availabilityObserver === availabilityObserver }) {
if !availabilityObservers.contains(where: { $0.availabilityObserver === availabilityObserver }) {
availabilityObservers.append(BKWeakAvailabilityObserver(availabilityObserver: availabilityObserver))
}
}
Expand All @@ -145,7 +159,7 @@ public extension BKAvailabilityObservable {
- parameter availabilityObserver: The availability observer to remove.
*/
func removeAvailabilityObserver(_ availabilityObserver: BKAvailabilityObserver) {
if availabilityObservers.contains({ $0.availabilityObserver === availabilityObserver }) {
if availabilityObservers.contains(where: { $0.availabilityObserver === availabilityObserver }) {
availabilityObservers.remove(at: availabilityObservers.index(where: { $0 === availabilityObserver })!)
}
}
Expand Down
27 changes: 16 additions & 11 deletions Source/BKCBCentralManagerDelegateProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ internal protocol BKCBCentralManagerStateDelegate: class {
}

internal protocol BKCBCentralManagerDiscoveryDelegate: class {
func centralManager(_ central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber)
func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber)
}

internal protocol BKCBCentralManagerConnectionDelegate: class {
func centralManager(_ central: CBCentralManager, didConnectPeripheral peripheral: CBPeripheral)
func centralManager(_ central: CBCentralManager, didFailToConnectPeripheral peripheral: CBPeripheral, error: NSError?)
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?)
func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)
func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?)
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?)
}

internal class BKCBCentralManagerDelegateProxy: NSObject, CBCentralManagerDelegate {
Expand All @@ -62,19 +62,24 @@ internal class BKCBCentralManagerDelegateProxy: NSObject, CBCentralManagerDelega
stateDelegate?.centralManagerDidUpdateState(central)
}

internal func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : AnyObject], rssi RSSI: NSNumber) {
discoveryDelegate?.centralManager(central, didDiscoverPeripheral: peripheral, advertisementData: advertisementData, RSSI: RSSI)
internal func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) {
discoveryDelegate?.centralManager(central, didDiscover: peripheral, advertisementData: advertisementData, rssi: RSSI)
}

internal func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
connectionDelegate?.centralManager(central, didConnectPeripheral: peripheral)
connectionDelegate?.centralManager(central, didConnect: peripheral)
}

internal func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: NSError?) {
connectionDelegate?.centralManager(central, didFailToConnectPeripheral: peripheral, error: error)
internal func centralManager(_ central: CBCentralManager, didFailToConnect peripheral: CBPeripheral, error: Error?) {
connectionDelegate?.centralManager(central, didFailToConnect: peripheral, error: error)
}

internal func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {
internal func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: Error?) {
connectionDelegate?.centralManager(central, didDisconnectPeripheral: peripheral, error: error)
}





}
77 changes: 34 additions & 43 deletions Source/BKCBPeripheralDelegateProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import CoreBluetooth

internal protocol BKCBPeripheralDelegate: class {
func peripheralDidUpdateName(_ peripheral: CBPeripheral)
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: NSError?)
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?)
func peripheral(_ peripheral: CBPeripheral, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?)
func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?)
func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?)
func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?)
}

internal class BKCBPeripheralDelegateProxy: NSObject, CBPeripheralDelegate {
Expand All @@ -51,55 +51,46 @@ internal class BKCBPeripheralDelegateProxy: NSObject, CBPeripheralDelegate {
delegate?.peripheralDidUpdateName(peripheral)
}

internal func peripheral(_ peripheral: CBPeripheral, didModifyServices invalidatedServices: [CBService]) {
// print("peripheral: \(peripheral) didModifyServices invalidatedServices: \(invalidatedServices)")
}

internal func peripheralDidUpdateRSSI(_ peripheral: CBPeripheral, error: NSError?) {
// print("peripheralDidUpdateRSSI: \(peripheral), error: \(error)")
}

internal func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: NSError?) {
// print("peripheral: \(peripheral) didReadRSSI: \(RSSI), error: \(error)")
}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: NSError?) {
// print("peripheral: \(peripheral) didDiscoverServices error: \(error)")
internal func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
delegate?.peripheral(peripheral, didDiscoverServices: error)
}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverIncludedServicesFor service: CBService, error: NSError?) {
// print("peripheral: \(peripheral) didDiscoverIncludedServicesForService: \(service), error: \(error)")
internal func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
delegate?.peripheral(peripheral, didDiscoverCharacteristicsFor: service, error: error)
}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: NSError?) {
// print("peripheral: \(peripheral) didDiscoverCharacteristicsForService: \(service), error: \(error)")
delegate?.peripheral(peripheral, didDiscoverCharacteristicsForService: service, error: error)

internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
delegate?.peripheral(peripheral, didUpdateValueFor: characteristic, error: error)
}

internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: NSError?) {
// print("peripheral: \(peripheral) didUpdateValueForCharacteristic: \(characteristic), error: \(error)")
delegate?.peripheral(peripheral, didUpdateValueForCharacteristic: characteristic, error: error)

internal func peripheral(_ peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: NSError?) {
// print("peripheral: \(peripheral), didWriteValueForCharacteristic: \(characteristic), error: \(error)")

@nonobjc
internal func peripheral(_ peripheral: CBPeripheral, didWriteValueFor descriptor: CBDescriptor, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: NSError?) {
// print("peripheral: \(peripheral) didUpdateNotificationStateForCharacteristic: \(characteristic), error: \(error)")

@nonobjc
internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor descriptor: CBDescriptor, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverDescriptorsFor characteristic: CBCharacteristic, error: NSError?) {
// print("peripheral: \(peripheral) didDiscoverDescriptorsForCharacteristic: \(characteristic), error: \(error)")
internal func peripheral(_ peripheral: CBPeripheral, didDiscoverIncludedServicesFor service: CBService, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor descriptor: CBDescriptor, error: NSError?) {
// print("peripheral: \(peripheral) didUpdateValueForDescriptor: \(descriptor), error: \(error)")
internal func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didWriteValueFor descriptor: CBDescriptor, error: NSError?) {
// print("peripheral: \(peripheral) didWriteValueForDescriptor: \(descriptor), error: \(error)")

internal func peripheral(_ peripheral: CBPeripheral, didDiscoverDescriptorsFor characteristic: CBCharacteristic, error: Error?) {

}

internal func peripheral(_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {

}

}
34 changes: 15 additions & 19 deletions Source/BKCBPeripheralManagerDelegateProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import CoreBluetooth

internal protocol BKCBPeripheralManagerDelegate: class {
func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager)
func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: NSError?)
func peripheralManager(_ peripheral: CBPeripheralManager, didAddService service: CBService, error: NSError?)
func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?)
func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?)
func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didSubscribeToCharacteristic characteristic: CBCharacteristic)
func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didUnsubscribeFromCharacteristic characteristic: CBCharacteristic)
func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWriteRequests requests: [CBATTRequest])
Expand All @@ -50,45 +50,41 @@ internal class BKCBPeripheralManagerDelegateProxy: NSObject, CBPeripheralManager
// MARK: CBPeripheralManagerDelegate

internal func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager) {
// print("peripheralManagerDidUpdateState: \(peripheral)")
// print("peripheralManagerDidUpdateState: \(peripheral)")
delegate?.peripheralManagerDidUpdateState(peripheral)
}

internal func peripheralManager(_ peripheral: CBPeripheralManager, willRestoreState dict: [String : AnyObject]) {
// print("peripheralManager: \(peripheral) willRestoreState: \(dict)")
}

internal func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: NSError?) {
// print("peripheralManagerDidStartAdvertising: \(peripheral) error: \(error)")

internal func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?) {
// print("peripheralManagerDidStartAdvertising: \(peripheral) error: \(error)")
delegate?.peripheralManagerDidStartAdvertising(peripheral, error: error)
}

internal func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: NSError?) {
// print("peripheralManager: \(peripheral) didAddService: \(service) error: \(error)")
delegate?.peripheralManager(peripheral, didAddService: service, error: error)
internal func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?) {
// print("peripheralManager: \(peripheral) didAddService: \(service) error: \(error)")
delegate?.peripheralManager(peripheral, didAdd: service, error: error)
}

internal func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didSubscribeTo characteristic: CBCharacteristic) {
// print("peripheralManager: \(peripheral) central: \(central) didSubscribeToCharacteristic: \(characteristic)")
// print("peripheralManager: \(peripheral) central: \(central) didSubscribeToCharacteristic: \(characteristic)")
delegate?.peripheralManager(peripheral, central: central, didSubscribeToCharacteristic: characteristic)
}

internal func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didUnsubscribeFrom characteristic: CBCharacteristic) {
// print("peripheralManager: \(peripheral) central: \(central) didUnsubscribeFromCharacteristic: \(characteristic)")
// print("peripheralManager: \(peripheral) central: \(central) didUnsubscribeFromCharacteristic: \(characteristic)")
delegate?.peripheralManager(peripheral, central: central, didUnsubscribeFromCharacteristic: characteristic)
}

internal func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveRead request: CBATTRequest) {
// print("peripheralManager: \(peripheral) didReceiveReadRequest: \(request)")
// print("peripheralManager: \(peripheral) didReceiveReadRequest: \(request)")
}

internal func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest]) {
// print("peripheralManager: \(peripheral) didReceiveWriteRequests: \(requests)")
// print("peripheralManager: \(peripheral) didReceiveWriteRequests: \(requests)")
delegate?.peripheralManager(peripheral, didReceiveWriteRequests: requests)
}

internal func peripheralManagerIsReady(toUpdateSubscribers peripheral: CBPeripheralManager) {
// print("peripheralManagerIsReadyToUpdateSubscribers: \(peripheral)")
// print("peripheralManagerIsReadyToUpdateSubscribers: \(peripheral)")
delegate?.peripheralManagerIsReadyToUpdateSubscribers(peripheral)
}

Expand Down
Loading

0 comments on commit b502d0a

Please sign in to comment.