From 236ebc98de41ad697ab3df1da158fe1d53795b96 Mon Sep 17 00:00:00 2001 From: Alsey Coleman Miller Date: Sat, 31 Mar 2018 08:33:55 -0500 Subject: [PATCH] Added Array extensions --- Sources/ATTConnection.swift | 12 ------------ Sources/Array.swift | 19 +++++++++++++++++++ Sources/UUID.swift | 4 ++-- Tests/BluetoothTests/BluetoothTests.swift | 12 +++++++++++- Xcode/Bluetooth.xcodeproj/project.pbxproj | 10 ++++++++++ 5 files changed, 42 insertions(+), 15 deletions(-) create mode 100644 Sources/Array.swift diff --git a/Sources/ATTConnection.swift b/Sources/ATTConnection.swift index 41a16548e..299004ea7 100755 --- a/Sources/ATTConnection.swift +++ b/Sources/ATTConnection.swift @@ -632,15 +632,3 @@ private struct ATTNotify: ATTNotifyType { self.notify = notify } } - -extension Array { - - mutating func popFirst() -> Element? { - - guard let first = self.first else { return nil } - - self.removeFirst() - - return first - } -} diff --git a/Sources/Array.swift b/Sources/Array.swift new file mode 100644 index 000000000..d18647b71 --- /dev/null +++ b/Sources/Array.swift @@ -0,0 +1,19 @@ +// +// Array.swift +// Bluetooth +// +// Created by Alsey Coleman Miller on 3/31/18. +// Copyright © 2018 PureSwift. All rights reserved. +// + +internal extension Array { + + mutating func popFirst() -> Element? { + + guard let first = self.first else { return nil } + + self.removeFirst() + + return first + } +} diff --git a/Sources/UUID.swift b/Sources/UUID.swift index dd93d23b6..8bf375c0d 100644 --- a/Sources/UUID.swift +++ b/Sources/UUID.swift @@ -8,7 +8,7 @@ import Foundation -extension UUID { +public extension UUID { public static var length: Int { return 16 } public static var stringLength: Int { return 36 } @@ -47,7 +47,7 @@ extension UUID: RawRepresentable { } } -extension UUID { +public extension UUID { public init?(data: Data) { diff --git a/Tests/BluetoothTests/BluetoothTests.swift b/Tests/BluetoothTests/BluetoothTests.swift index 39e4f750a..26e65f0e8 100755 --- a/Tests/BluetoothTests/BluetoothTests.swift +++ b/Tests/BluetoothTests/BluetoothTests.swift @@ -23,7 +23,8 @@ final class BluetoothTests: XCTestCase { ("testUUIDStringParsePerformance", testUUIDStringParsePerformance), ("testUUIDStringPerformance", testUUIDStringPerformance), ("testUUIDDataParsePerformance", testUUIDDataParsePerformance), - ("testUUIDDataPerformance", testUUIDDataPerformance) + ("testUUIDDataPerformance", testUUIDDataPerformance), + ("testUInt128", testUInt128) ] func testAddress() { @@ -41,6 +42,15 @@ final class BluetoothTests: XCTestCase { XCTAssert(address.hashValue != 0) } + func testUInt128() { + + let uuid = UUID(rawValue: "60F14FE2-F972-11E5-B84F-23E070D5A8C7")! + + let value = UInt128(uuid: uuid) + + XCTAssert(value.description == "60F14FE2F97211E5B84F23E070D5A8C7") + } + func testUUID() { do { diff --git a/Xcode/Bluetooth.xcodeproj/project.pbxproj b/Xcode/Bluetooth.xcodeproj/project.pbxproj index ad07060cc..3bc7dd236 100644 --- a/Xcode/Bluetooth.xcodeproj/project.pbxproj +++ b/Xcode/Bluetooth.xcodeproj/project.pbxproj @@ -202,6 +202,10 @@ 6ECBCF19206FBD0F00312117 /* HCICommandTimeout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ECBCF17206FBD0F00312117 /* HCICommandTimeout.swift */; }; 6ECBCF1A206FBD0F00312117 /* HCICommandTimeout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ECBCF17206FBD0F00312117 /* HCICommandTimeout.swift */; }; 6ECBCF1B206FBD0F00312117 /* HCICommandTimeout.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ECBCF17206FBD0F00312117 /* HCICommandTimeout.swift */; }; + 6ECBCF21206FC3A200312117 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ECBCF20206FC3A200312117 /* Array.swift */; }; + 6ECBCF22206FC3A200312117 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ECBCF20206FC3A200312117 /* Array.swift */; }; + 6ECBCF23206FC3A200312117 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ECBCF20206FC3A200312117 /* Array.swift */; }; + 6ECBCF24206FC3A200312117 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6ECBCF20206FC3A200312117 /* Array.swift */; }; 6EE84DBB1CAF5C7C00A40C4D /* Bluetooth.h in Headers */ = {isa = PBXBuildFile; fileRef = 6EE84DBA1CAF5C7C00A40C4D /* Bluetooth.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6EE84DC21CAF5C7C00A40C4D /* Bluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 6EE84DB71CAF5C7C00A40C4D /* Bluetooth.framework */; }; 6EE84DD51CAF603000A40C4D /* BluetoothUUID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6EE84DD41CAF603000A40C4D /* BluetoothUUID.swift */; }; @@ -319,6 +323,7 @@ 6EB45EEF2001398100AE5A42 /* DefinedUUID.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DefinedUUID.swift; sourceTree = ""; }; 6ECBCF0A206E683C00312117 /* L2CAPSocket.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = L2CAPSocket.swift; sourceTree = ""; }; 6ECBCF17206FBD0F00312117 /* HCICommandTimeout.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HCICommandTimeout.swift; sourceTree = ""; }; + 6ECBCF20206FC3A200312117 /* Array.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 6EE84DB71CAF5C7C00A40C4D /* Bluetooth.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Bluetooth.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6EE84DBA1CAF5C7C00A40C4D /* Bluetooth.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Bluetooth.h; sourceTree = ""; }; 6EE84DBC1CAF5C7C00A40C4D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -446,6 +451,7 @@ 6E704C821E95C41C00484A22 /* Integer.swift */, 6E704C831E95C41C00484A22 /* Range.swift */, 6E704C971E95C6A500484A22 /* UUID.swift */, + 6ECBCF20206FC3A200312117 /* Array.swift */, ); name = Extensions; sourceTree = ""; @@ -840,6 +846,7 @@ 6E49B24A20532D45002EA5DC /* Range.swift in Sources */, 6E49B24B20532D45002EA5DC /* BitMaskOption.swift in Sources */, 6E49B24C20532D45002EA5DC /* ByteValue.swift in Sources */, + 6ECBCF24206FC3A200312117 /* Array.swift in Sources */, 6E49B24D20532D45002EA5DC /* Address.swift in Sources */, 6E49B24E20532D45002EA5DC /* HCIGeneralEventParameter.swift in Sources */, 6E60A2C22068928400E42351 /* BluetoothHostController.swift in Sources */, @@ -904,6 +911,7 @@ 6E704C891E95C41C00484A22 /* Range.swift in Sources */, 6E704C791E95C32D00484A22 /* BitMaskOption.swift in Sources */, 6E704C7D1E95C34D00484A22 /* ByteValue.swift in Sources */, + 6ECBCF23206FC3A200312117 /* Array.swift in Sources */, 6EB2EA0E1CD5A8A7000CF975 /* Address.swift in Sources */, 6EB2EA0F1CD5A8A7000CF975 /* HCIGeneralEventParameter.swift in Sources */, 6E60A2C12068928400E42351 /* BluetoothHostController.swift in Sources */, @@ -971,6 +979,7 @@ 6E32291A1FCE45480035605D /* AdvertisingChannelHeader.swift in Sources */, 6E60A2BF2068928400E42351 /* BluetoothHostController.swift in Sources */, 6E704C7B1E95C34D00484A22 /* ByteValue.swift in Sources */, + 6ECBCF21206FC3A200312117 /* Array.swift in Sources */, 6EB45EF02001398100AE5A42 /* DefinedUUID.swift in Sources */, 6EE84DFC1CAF891E00A40C4D /* LowEnergyEventParameter.swift in Sources */, 6EE84E011CAF891E00A40C4D /* LowEnergyCommandParameter.swift in Sources */, @@ -1045,6 +1054,7 @@ 6E704C881E95C41C00484A22 /* Range.swift in Sources */, 6E704C781E95C32D00484A22 /* BitMaskOption.swift in Sources */, 6E704C7C1E95C34D00484A22 /* ByteValue.swift in Sources */, + 6ECBCF22206FC3A200312117 /* Array.swift in Sources */, 6EF45FAE1CC6D04D001F7A39 /* Address.swift in Sources */, 6EF45FAF1CC6D04D001F7A39 /* HCIGeneralEventParameter.swift in Sources */, 6E60A2C02068928400E42351 /* BluetoothHostController.swift in Sources */,