Skip to content

Commit 689b15e

Browse files
committed
Clean code
1 parent 8b8215e commit 689b15e

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

SDK/BLEDevice.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public class BLEDevice: NSObject, CBPeripheralDelegate {
4040
guard peripheral.state == .Disconnected else { return false }
4141
centralManager.connectPeripheral(peripheral, options: nil)
4242
connectionTimeoutTimer?.invalidate()
43-
connectionTimeoutTimer = NSTimer.scheduledTimerWithTimeInterval(connectionTimeoutInterval, target: self, selector: "didConnectTimeout", userInfo: nil, repeats: false)
43+
connectionTimeoutTimer = NSTimer.scheduledTimerWithTimeInterval(connectionTimeoutInterval, target: self, selector: #selector(self.didConnectTimeout), userInfo: nil, repeats: false)
4444
return true
4545
}
4646

SDK/BLEDiscoveryManager.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ private class UnreachableDevicesDetector {
200200
previouslyDiscoveredDevices = Set()
201201
currentlyDiscoveredDevices = Set()
202202
unreachableDevicesDetectionTimer?.invalidate()
203-
unreachableDevicesDetectionTimer = NSTimer.scheduledTimerWithTimeInterval(minDetectionInterval + 0.5, target: self, selector: "removeUnreachableDevices", userInfo: nil, repeats: true)
203+
unreachableDevicesDetectionTimer = NSTimer.scheduledTimerWithTimeInterval(minDetectionInterval + 0.5, target: self, selector: #selector(self.removeUnreachableDevices), userInfo: nil, repeats: true)
204204
}
205205

206206
func stop() {

SDK/NuimoBluetoothController.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ private class LEDMatrixWriter {
171171
// When the matrix write response is not retrieved within 500ms we assume the response to have timed out
172172
dispatch_async(dispatch_get_main_queue()) {
173173
self.writeMatrixResponseTimeoutTimer?.invalidate()
174-
self.writeMatrixResponseTimeoutTimer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: "didRetrieveMatrixWriteResponse", userInfo: nil, repeats: false)
174+
self.writeMatrixResponseTimeoutTimer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: #selector(self.didRetrieveMatrixWriteResponse), userInfo: nil, repeats: false)
175175
}
176176
}
177177

@@ -298,11 +298,11 @@ private extension NuimoGestureEvent {
298298

299299
private extension NuimoLEDMatrix {
300300
var matrixBytes: [UInt8] {
301-
return bits
301+
return leds
302302
.chunk(8)
303303
.map{ $0
304304
.enumerate()
305-
.map{(i: Int, b: Bit) -> Int in return b == Bit.Zero ? 0 : 1 << i}
305+
.map{(i: Int, b: Bool) -> Int in return b ? 1 << i : 0}
306306
.reduce(UInt8(0), combine: {(s: UInt8, v: Int) -> UInt8 in s + UInt8(v)})
307307
}
308308
}
@@ -317,7 +317,8 @@ private extension SequenceType {
317317
var i = n
318318
self.forEach {
319319
chunk.append($0)
320-
if --i == 0 {
320+
i -= 1
321+
if i == 0 {
321322
chunks.append(chunk)
322323
chunk.removeAll(keepCapacity: true)
323324
i = n

SDK/NuimoLEDMatrix.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ public let NuimoLEDMatrixDefaultLEDOffCharacter = NuimoLEDMatrixLEDOffCharacters
1414
public let NuimoLEDMatrixDefaultLEDOnCharacter: Character = "."
1515

1616
public class NuimoLEDMatrix: NSObject {
17-
public let bits: [Bit]
17+
public let leds: [Bool]
1818

1919
public init(matrix: NuimoLEDMatrix) {
20-
bits = matrix.bits
20+
leds = matrix.leds
2121
}
2222

2323
public init(string: String) {
24-
bits = string
24+
leds = string
2525
// Cut off after count of LEDs
2626
.substringToIndex(string.startIndex.advancedBy(min(string.characters.count, NuimoLEDMatrixLEDCount)))
2727
// Right fill up to count of LEDs
2828
.stringByPaddingToLength(NuimoLEDMatrixLEDCount, withString: " ", startingAtIndex: 0)
2929
.characters
30-
.map{NuimoLEDMatrixLEDOffCharacters.contains($0) ? Bit.Zero : Bit.One}
30+
.map{!NuimoLEDMatrixLEDOffCharacters.contains($0)}
3131
}
3232

3333
//TODO: Have only one init(progress) method and pass presentation style as 2nd argument
@@ -53,7 +53,7 @@ public class NuimoLEDMatrix: NSObject {
5353
}
5454

5555
public func ==(left: NuimoLEDMatrix, right: NuimoLEDMatrix) -> Bool {
56-
return left.bits == right.bits
56+
return left.leds == right.leds
5757
}
5858

5959
public func ==(left: NuimoLEDMatrix?, right: NuimoLEDMatrix) -> Bool {

0 commit comments

Comments
 (0)