Skip to content

Commit

Permalink
Updated repo for Xcode 15 and re-formatted (#65)
Browse files Browse the repository at this point in the history
- Ran XCode auto-upgrade
- Bumped to latest swift-format config
- Formatted with latest swift-format rules
  • Loading branch information
sureshjoshi authored Nov 17, 2023
1 parent 9c6ff9d commit 6554843
Show file tree
Hide file tree
Showing 28 changed files with 491 additions and 319 deletions.
13 changes: 13 additions & 0 deletions .swift-format
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
"lineBreakBeforeEachGenericRequirement" : false,
"lineLength" : 100,
"maximumBlankLines" : 1,
"multiElementCollectionTrailingCommas" : true,
"noAssignmentInExpressions" : {
"allowedFunctions" : [
"XCTAssertNoThrow"
]
},
"prioritizeKeepingFunctionOutputTogether" : false,
"respectsExistingLineBreaks" : true,
"rules" : {
"AllPublicDeclarationsHaveDocumentation" : false,
"AlwaysUseLiteralForEmptyCollectionInit" : false,
"AlwaysUseLowerCamelCase" : true,
"AmbiguousTrailingClosureOverload" : true,
"BeginDocumentationCommentWithOneLineSummary" : false,
Expand All @@ -30,18 +37,23 @@
"NeverUseForceTry" : false,
"NeverUseImplicitlyUnwrappedOptionals" : false,
"NoAccessLevelOnExtensionDeclaration" : true,
"NoAssignmentInExpressions" : true,
"NoBlockComments" : true,
"NoCasesWithOnlyFallthrough" : true,
"NoEmptyTrailingClosureParentheses" : true,
"NoLabelsInCasePatterns" : true,
"NoLeadingUnderscores" : false,
"NoParensAroundConditions" : true,
"NoPlaygroundLiterals" : true,
"NoVoidReturnOnFunctionSignature" : true,
"OmitExplicitReturns" : false,
"OneCasePerLine" : true,
"OneVariableDeclarationPerLine" : true,
"OnlyOneTrailingClosureArgument" : true,
"OrderedImports" : true,
"ReplaceForEachWithForLoop" : true,
"ReturnVoidInsteadOfEmptyTuple" : true,
"TypeNamesShouldBeCapitalized" : true,
"UseEarlyExits" : false,
"UseLetInEveryBoundCaseVariable" : true,
"UseShorthandTypeNames" : true,
Expand All @@ -51,6 +63,7 @@
"UseWhereClausesInForLoops" : false,
"ValidateDocumentationComments" : false
},
"spacesAroundRangeFormationOperators" : false,
"tabWidth" : 4,
"version" : 1
}
4 changes: 2 additions & 2 deletions Examples/Central/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ let package = Package(
.macOS(.v10_15),
],
dependencies: [
.package(name: "SwiftyTeeth", path: "../../"),
.package(name: "SwiftyTeeth", path: "../../")
],
targets: [
.executableTarget(
name: "Central",
dependencies: ["SwiftyTeeth"]),
dependencies: ["SwiftyTeeth"])
]
)
1 change: 0 additions & 1 deletion Examples/Central/Sources/Central/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,4 @@ instance.stateChangedHandler = { (state) in
}
}


RunLoop.main.run()
4 changes: 2 additions & 2 deletions Examples/Peripheral/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ let package = Package(
.macOS(.v10_15),
],
dependencies: [
.package(name: "SwiftyTeeth", path: "../../"),
.package(name: "SwiftyTeeth", path: "../../")
],
targets: [
.executableTarget(
name: "Peripheral",
dependencies: [.product(name: "SwiftyTooth", package: "SwiftyTeeth")]),
dependencies: [.product(name: "SwiftyTooth", package: "SwiftyTeeth")])
]
)
2 changes: 1 addition & 1 deletion Examples/Peripheral/Sources/Peripheral/logger.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// logger.swift
//
//
//
// Created by SJ on 2020-03-27.
//
Expand Down
18 changes: 9 additions & 9 deletions Examples/Peripheral/Sources/Peripheral/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// Created by SJ on 2020-03-27.
//


import Foundation
import SwiftyTooth

Expand Down Expand Up @@ -35,33 +34,34 @@ let tx = Characteristic(
properties: [
.write(onWrite: { (request, response) in
print("In on onWrite \(String(describing: request))")

guard let value = request,
value.count == 1 else {
value.count == 1
else {
print("No data available")
// TODO: Failure response?
return
}
// TODO: Clean up this UInt8

// TODO: Clean up this UInt8
increment(by: [UInt8](value)[0])

// If increment is really long, this could technically time out - should increment the counter, respond success, THEN notify
response(.success(()))
}),

.writeNoResponse(onWrite: { (request) in
print("In on onWriteNoResponse \(String(describing: request))")
})
}),
]
)

var counter = UInt8.min
func increment(by value: UInt8) {
for _ in 0..<128 { // Sending 128 elements to test notification queue
for _ in 0..<128 { // Sending 128 elements to test notification queue
counter += value
let data = Data([counter])
instance.emit(data: data, on: rx)
_ = instance.emit(data: data, on: rx)
}
}

Expand Down
7 changes: 3 additions & 4 deletions Sources/Common/Characteristic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public enum Property {
case notify(onNotify: NotifyHandler)
case write(onWrite: WriteHandler)
case writeNoResponse(onWrite: WriteNoResponseHandler)

var isReadable: Bool {
switch self {
case .read, .notify:
Expand All @@ -28,7 +28,7 @@ public enum Property {
return false
}
}

var isWriteable: Bool {
return !isReadable
}
Expand All @@ -37,8 +37,7 @@ public enum Property {
public struct Characteristic {
public let uuid: UUID
public let properties: [Property]



public init(uuid: UUID, properties: [Property]) {
self.uuid = uuid
self.properties = properties
Expand Down
64 changes: 32 additions & 32 deletions Sources/Common/Deque.swift
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
/*
Briefly using a Dequeue from Ray Wenderlich to test out the notification queue. Need to create a
"proper" queue with a thread-safe implementation, and a valid "peek" down the road... (Issue #45)
https://github.com/raywenderlich/swift-algorithm-club/tree/master/Deque
Deque (pronounced "deck"), a double-ended queue
This particular implementation is simple but not very efficient. Several
operations are O(n). A more efficient implementation would use a doubly
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
}
public var isEmpty: Bool {
return array.isEmpty
}

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

public mutating func enqueue(_ element: T) {
array.append(element)
}
public mutating func enqueue(_ element: T) {
array.append(element)
}

public mutating func enqueueFront(_ element: T) {
array.insert(element, at: 0)
}
public mutating func enqueueFront(_ element: T) {
array.insert(element, at: 0)
}

public mutating func dequeue() -> T? {
if isEmpty {
return nil
} else {
return array.removeFirst()
public mutating func dequeue() -> T? {
if isEmpty {
return nil
} else {
return array.removeFirst()
}
}
}

public mutating func dequeueBack() -> T? {
if isEmpty {
return nil
} else {
return array.removeLast()
public mutating func dequeueBack() -> T? {
if isEmpty {
return nil
} else {
return array.removeLast()
}
}
}

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

public func peekBack() -> T? {
return array.last
}
public func peekBack() -> T? {
return array.last
}
}
2 changes: 1 addition & 1 deletion Sources/Common/Service.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation
public struct Service {
public let uuid: UUID
public let characteristics: [Characteristic]

public init(uuid: UUID, characteristics: [Characteristic]) {
self.uuid = uuid
self.characteristics = characteristics
Expand Down
Loading

0 comments on commit 6554843

Please sign in to comment.