Skip to content

Commit

Permalink
Merge pull request rhummelmose#41 from calebkleveter/swift-3
Browse files Browse the repository at this point in the history
Finished conversion to Swift 3.
  • Loading branch information
rhummelmose authored Aug 17, 2016
2 parents 8059af7 + d0d882f commit f3423b3
Show file tree
Hide file tree
Showing 24 changed files with 382 additions and 355 deletions.
8 changes: 7 additions & 1 deletion BluetoothKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -287,14 +287,15 @@
attributes = {
LastSwiftMigration = 0710;
LastSwiftUpdateCheck = 0710;
LastUpgradeCheck = 0700;
LastUpgradeCheck = 0800;
ORGANIZATIONNAME = "Rasmus Taulborg Hummelmose";
TargetAttributes = {
C64CDDF21BE4C46A00F72549 = {
CreatedOnToolsVersion = 7.1;
};
C687E3971B8B496400B702D8 = {
CreatedOnToolsVersion = 7.0;
LastSwiftMigration = 0800;
};
C6ED86C01BA955A600C9B70B = {
CreatedOnToolsVersion = 7.1;
Expand Down Expand Up @@ -490,6 +491,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.rasmusth.BluetoothKit;
SDKROOT = appletvos;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
TARGETED_DEVICE_FAMILY = 3;
TVOS_DEPLOYMENT_TARGET = 9.0;
};
Expand Down Expand Up @@ -600,6 +602,7 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.rasmusth.BluetoothKit;
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -615,6 +618,8 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.rasmusth.BluetoothKit;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down Expand Up @@ -653,6 +658,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.rasmusth.BluetoothKit;
SDKROOT = macosx;
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0700"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0710"
LastUpgradeVersion = "0800"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
72 changes: 38 additions & 34 deletions Source/BKAvailability.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ import CoreBluetooth

public func == (lhs: BKAvailability, rhs: BKAvailability) -> Bool {
switch (lhs, rhs) {
case (.Available, .Available): return true
case (.Unavailable(cause: .Any), .Unavailable): return true
case (.Unavailable, .Unavailable(cause: .Any)): return true
case (.Unavailable(let lhsCause), .Unavailable(let rhsCause)): return lhsCause == rhsCause
case (.available, .available): return true
case (.unavailable(cause: .any), .unavailable): return true
case (.unavailable, .unavailable(cause: .any)): return true
case (.unavailable(let lhsCause), .unavailable(let rhsCause)): return lhsCause == rhsCause
default: return false
}
}
Expand All @@ -44,20 +44,22 @@ public func == (lhs: BKAvailability, rhs: BKAvailability) -> Bool {
*/
public enum BKAvailability: Equatable {

case Available
case Unavailable(cause: BKUnavailabilityCause)
case available
case unavailable(cause: BKUnavailabilityCause)

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

internal init(peripheralManagerState: CBPeripheralManagerState) {
@available(iOS 10.0, *)
internal init(peripheralManagerState: CBManagerState) {
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 @@ -73,32 +75,34 @@ public enum BKAvailability: Equatable {
*/
public enum BKUnavailabilityCause: NilLiteralConvertible {

case Any
case Resetting
case Unsupported
case Unauthorized
case PoweredOff
case any
case resetting
case unsupported
case unauthorized
case poweredOff

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

internal init(centralManagerState: CBCentralManagerState) {
@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
case .poweredOff: self = poweredOff
case .resetting: self = resetting
case .unauthorized: self = unauthorized
case .unsupported: self = unsupported
default: self = nil
}
}

internal init(peripheralManagerState: CBPeripheralManagerState) {
@available(iOS 10.0, *)
internal init(peripheralManagerState: CBManagerState) {
switch peripheralManagerState {
case .PoweredOff: self = PoweredOff
case .Resetting: self = Resetting
case .Unauthorized: self = Unauthorized
case .Unsupported: self = Unsupported
case .poweredOff: self = poweredOff
case .resetting: self = resetting
case .unauthorized: self = unauthorized
case .unsupported: self = unsupported
default: self = nil
}
}
Expand All @@ -110,8 +114,8 @@ public enum BKUnavailabilityCause: NilLiteralConvertible {
*/
public protocol BKAvailabilityObservable: class {
var availabilityObservers: [BKWeakAvailabilityObserver] { get set }
func addAvailabilityObserver(availabilityObserver: BKAvailabilityObserver)
func removeAvailabilityObserver(availabilityObserver: BKAvailabilityObserver)
func addAvailabilityObserver(_ availabilityObserver: BKAvailabilityObserver)
func removeAvailabilityObserver(_ availabilityObserver: BKAvailabilityObserver)
}

/**
Expand All @@ -130,7 +134,7 @@ public extension BKAvailabilityObservable {
Add a new availability observer. The observer will be weakly stored. If the observer is already subscribed the call will be ignored.
- parameter availabilityObserver: The availability observer to add.
*/
func addAvailabilityObserver(availabilityObserver: BKAvailabilityObserver) {
func addAvailabilityObserver(_ availabilityObserver: BKAvailabilityObserver) {
if !availabilityObservers.contains({ $0.availabilityObserver === availabilityObserver }) {
availabilityObservers.append(BKWeakAvailabilityObserver(availabilityObserver: availabilityObserver))
}
Expand All @@ -140,7 +144,7 @@ public extension BKAvailabilityObservable {
Remove an availability observer. If the observer isn't subscribed the call will be ignored.
- parameter availabilityObserver: The availability observer to remove.
*/
func removeAvailabilityObserver(availabilityObserver: BKAvailabilityObserver) {
func removeAvailabilityObserver(_ availabilityObserver: BKAvailabilityObserver) {
if availabilityObservers.contains({ $0.availabilityObserver === availabilityObserver }) {
availabilityObservers.remove(at: availabilityObservers.index(where: { $0 === availabilityObserver })!)
}
Expand All @@ -158,12 +162,12 @@ public protocol BKAvailabilityObserver: class {
- parameter availabilityObservable: The object that registered the availability change.
- parameter availability: The new availability value.
*/
func availabilityObserver(availabilityObservable: BKAvailabilityObservable, availabilityDidChange availability: BKAvailability)
func availabilityObserver(_ availabilityObservable: BKAvailabilityObservable, availabilityDidChange availability: BKAvailability)

/**
Informs the observer that the cause of Bluetooth LE unavailability changed.
- parameter availabilityObservable: The object that registered the cause change.
- parameter unavailabilityCause: The new cause of unavailability.
*/
func availabilityObserver(availabilityObservable: BKAvailabilityObservable, unavailabilityCauseDidChange unavailabilityCause: BKUnavailabilityCause)
func availabilityObserver(_ availabilityObservable: BKAvailabilityObservable, unavailabilityCauseDidChange unavailabilityCause: BKUnavailabilityCause)
}
20 changes: 10 additions & 10 deletions Source/BKCBCentralManagerDelegateProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,17 @@ import Foundation
import CoreBluetooth

internal protocol BKCBCentralManagerStateDelegate: class {
func centralManagerDidUpdateState(central: CBCentralManager)
func centralManagerDidUpdateState(_ central: CBCentralManager)
}

internal protocol BKCBCentralManagerDiscoveryDelegate: class {
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber)
func centralManager(_ central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], 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, didConnectPeripheral peripheral: CBPeripheral)
func centralManager(_ central: CBCentralManager, didFailToConnectPeripheral peripheral: CBPeripheral, error: NSError?)
func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?)
}

internal class BKCBCentralManagerDelegateProxy: NSObject, CBCentralManagerDelegate {
Expand All @@ -58,23 +58,23 @@ internal class BKCBCentralManagerDelegateProxy: NSObject, CBCentralManagerDelega

// MARK: CBCentralManagerDelegate

internal func centralManagerDidUpdateState(central: CBCentralManager) {
internal func centralManagerDidUpdateState(_ central: CBCentralManager) {
stateDelegate?.centralManagerDidUpdateState(central)
}

internal func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) {
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, didConnectPeripheral peripheral: CBPeripheral) {
internal func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) {
connectionDelegate?.centralManager(central, didConnectPeripheral: peripheral)
}

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

internal func centralManager(central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {
internal func centralManager(_ central: CBCentralManager, didDisconnectPeripheral peripheral: CBPeripheral, error: NSError?) {
connectionDelegate?.centralManager(central, didDisconnectPeripheral: peripheral, error: error)
}
}
34 changes: 17 additions & 17 deletions Source/BKCBPeripheralDelegateProxy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ import Foundation
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 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?)
}

internal class BKCBPeripheralDelegateProxy: NSObject, CBPeripheralDelegate {
Expand All @@ -46,59 +46,59 @@ internal class BKCBPeripheralDelegateProxy: NSObject, CBPeripheralDelegate {

// MARK: CBPeripheralDelegate

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

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

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

internal func peripheral(peripheral: CBPeripheral, didReadRSSI RSSI: NSNumber, error: NSError?) {
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?) {
internal func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: NSError?) {
// print("peripheral: \(peripheral) didDiscoverServices error: \(error)")
delegate?.peripheral(peripheral, didDiscoverServices: error)
}

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

internal func peripheral(peripheral: CBPeripheral, didDiscoverCharacteristicsForService service: CBService, error: NSError?) {
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, didUpdateValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) {
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, didWriteValueForCharacteristic characteristic: CBCharacteristic, error: NSError?) {
internal func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: NSError?) {
// print("peripheral: \(peripheral), didWriteValueForCharacteristic: \(characteristic), error: \(error)")
}

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

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

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

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

Expand Down
Loading

0 comments on commit f3423b3

Please sign in to comment.