Skip to content

Commit

Permalink
See issue #66: Ran preliminary swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
sureshjoshi committed Dec 23, 2023
1 parent 6554843 commit 0979d9d
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 38 deletions.
4 changes: 2 additions & 2 deletions .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : true,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
Expand All @@ -46,7 +46,7 @@
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : false,
"OmitExplicitReturns" : true,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/Characteristic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public enum Property {
}

var isWriteable: Bool {
return !isReadable
!isReadable
}
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/Common/Deque.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
linked list or a circular buffer.
*/
public struct Deque<T> {
private var array = [T]()
private var array: [T] = []

public var isEmpty: Bool {
return array.isEmpty
array.isEmpty
}

public var count: Int {
return array.count
array.count
}

public mutating func enqueue(_ element: T) {
Expand Down Expand Up @@ -44,10 +44,10 @@ public struct Deque<T> {
}

public func peekFront() -> T? {
return array.first
array.first
}

public func peekBack() -> T? {
return array.last
array.last
}
}
12 changes: 6 additions & 6 deletions Sources/SwiftyTeeth/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ open class Device: NSObject {
fileprivate let tag = "SwiftyDevice"

let peripheral: CBPeripheral
var discoveredServices = [UUID: Service]()
var discoveredServices: [UUID: Service] = [:]

private let manager: SwiftyTeeth

Expand All @@ -37,7 +37,7 @@ open class Device: NSObject {
}

private var connectionHandler: ((ConnectionState) -> Void)?
private var notificationHandler = [CBCharacteristic: ((Result<Data, Error>) -> Void)]()
private var notificationHandler: [CBCharacteristic: ((Result<Data, Error>) -> Void)] = [:]

// Connection parameters
fileprivate var autoReconnect = false
Expand Down Expand Up @@ -77,15 +77,15 @@ extension Device {
}

public var isConnected: Bool {
return connectionState == .connected
connectionState == .connected
}

public var name: String {
return peripheral.name ?? ""
peripheral.name ?? ""
}

public var id: String {
return peripheral.identifier.uuidString
peripheral.identifier.uuidString
}

// open var rssi: Int {
Expand Down Expand Up @@ -295,7 +295,7 @@ extension Device {
// MARK: - NSObject overrides
extension Device {
open override var hash: Int {
return id.hash
id.hash
}

open override func isEqual(_ object: Any?) -> Bool {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SwiftyTeeth/Extensions/CBCharacterisic+String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ extension CBCharacteristic {
}

func equals(_ uuidString: String) -> Bool {
return self.uuid.uuidString.lowercased() == uuidString.lowercased()
self.uuid.uuidString.lowercased() == uuidString.lowercased()
}
}

extension Array where Element: CBCharacteristic {
func find(uuidString: String) -> CBCharacteristic? {
return self.first(where: { $0.equals(uuidString) })
self.first(where: { $0.equals(uuidString) })
}
}
4 changes: 2 additions & 2 deletions Sources/SwiftyTeeth/Extensions/CBService+String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import CoreBluetooth

extension CBService {
func equals(_ uuidString: String) -> Bool {
return self.uuid.uuidString.lowercased() == uuidString.lowercased()
self.uuid.uuidString.lowercased() == uuidString.lowercased()
}
}

extension Array where Element: CBService {
func find(uuidString: String) -> CBService? {
return self.first(where: { $0.equals(uuidString) })
self.first(where: { $0.equals(uuidString) })
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
extension OperationQueue: SwiftyQueue {

var items: [Operation] {
return operations
operations
}

func pushBack(_ item: Operation) {
Expand Down
10 changes: 5 additions & 5 deletions Sources/SwiftyTeeth/QueueItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ private enum State: String {
case finishing = "Finishing" // On route to finished, but haven't notified Queue
case finished = "Finished"

fileprivate var keyPath: String { return "is" + self.rawValue }
fileprivate var keyPath: String { "is" + self.rawValue }
}

public class QueueItem<T>: Operation {
Expand All @@ -24,7 +24,7 @@ public class QueueItem<T>: Operation {
@available(*, deprecated, message: "Don't use this")
override open var completionBlock: (@Sendable () -> Void)? {
get {
return nil
nil
}
set {
fatalError(
Expand All @@ -33,9 +33,9 @@ public class QueueItem<T>: Operation {
}
}

override public var isAsynchronous: Bool { return true }
override public var isExecuting: Bool { return state == .executing }
override public var isFinished: Bool { return state == .finished }
override public var isAsynchronous: Bool { true }
override public var isExecuting: Bool { state == .executing }
override public var isFinished: Bool { state == .finished }

fileprivate var state = State.ready {
willSet {
Expand Down
8 changes: 4 additions & 4 deletions Sources/SwiftyTeeth/SwiftyTeeth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ open class SwiftyTeeth: NSObject {
}()

public var state: BluetoothState {
return BluetoothState(rawValue: centralManager.state.rawValue) ?? .unknown
BluetoothState(rawValue: centralManager.state.rawValue) ?? .unknown
}

// TODO: Hold a private set, and expose a list?
public var scannedDevices = Set<Device>()

public var isScanning: Bool {
return centralManager.isScanning
centralManager.isScanning
}

// TODO: Should be a list? Can connect to > 1 device
private var connectedDevices = [String: Device]()
private var connectedDevices: [String: Device] = [:]
private var scanChangesHandler: ((Device) -> Void)?
private var scanCompleteHandler: (([Device]) -> Void)?

Expand All @@ -51,7 +51,7 @@ open class SwiftyTeeth: NSObject {
extension SwiftyTeeth {
public class var logger: Logger? {
get {
return swiftyTeethLogger
swiftyTeethLogger
}
set {
swiftyTeethLogger = newValue
Expand Down
2 changes: 1 addition & 1 deletion Sources/SwiftyTeeth/SwiftyTeethable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ extension SwiftyTeethable {

/// Central and peripheral bluetooth manager.
public var swiftyTeeth: SwiftyTeeth {
return SwiftyTeeth.shared
SwiftyTeeth.shared
}
}
14 changes: 7 additions & 7 deletions Sources/SwiftyTooth/SwiftyTooth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ open class SwiftyTooth: NSObject {
// This is just used to determine if we should notify out values to a subscribed central
fileprivate var connectedCentral: String?
fileprivate var characteristics: [CBMutableCharacteristic] = []
fileprivate var notifyHandlers = [UUID: NotifyHandler]()
fileprivate var readHandlers = [UUID: ReadHandler]()
fileprivate var writeHandlers = [UUID: WriteHandler]()
fileprivate var writeNoResponseHandlers = [UUID: WriteNoResponseHandler]()
fileprivate var notifyHandlers: [UUID: NotifyHandler] = [:]
fileprivate var readHandlers: [UUID: ReadHandler] = [:]
fileprivate var writeHandlers: [UUID: WriteHandler] = [:]
fileprivate var writeNoResponseHandlers: [UUID: WriteNoResponseHandler] = [:]

// Using a very quick thread-unsafe queue just to test this out conceptually, to see how it works
fileprivate var notificationQueue = Deque<QueueItem>()
Expand All @@ -47,7 +47,7 @@ open class SwiftyTooth: NSObject {
}()

public var state: BluetoothState {
return BluetoothState(rawValue: peripheralManager.state.rawValue) ?? .unknown
BluetoothState(rawValue: peripheralManager.state.rawValue) ?? .unknown
}

public override init() {
Expand All @@ -57,7 +57,7 @@ open class SwiftyTooth: NSObject {
extension SwiftyTooth {
public class var logger: Logger? {
get {
return swiftyToothLogger
swiftyToothLogger
}
set {
swiftyToothLogger = newValue
Expand All @@ -69,7 +69,7 @@ extension SwiftyTooth {
extension SwiftyTooth {

public var isAdvertising: Bool {
return peripheralManager.isAdvertising
peripheralManager.isAdvertising
}

public func advertise(name: String, uuids: [CBUUID] = [], for timeout: TimeInterval = 0) {
Expand Down
2 changes: 1 addition & 1 deletion SwiftyTeeth-Sample/Extension/ScopingFunctions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ extension ScopingFunctions {
/// }
/// // TODO: Is this actually "let"?
@inline(__always) func with<R>(block: (Self) -> R) -> R {
return block(self)
block(self)
}
}

Expand Down
2 changes: 1 addition & 1 deletion SwiftyTeeth-Sample/ScanningView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SwiftyTeeth

final class ScanningViewModel: ObservableObject, SwiftyTeethable {
@Published var isScanning = false
@Published var peripherals = [Device]()
@Published var peripherals: [Device] = []

init() {
swiftyTeeth.stateChangedHandler = { (state) in
Expand Down

0 comments on commit 0979d9d

Please sign in to comment.