Skip to content

Commit 62bce31

Browse files
committed
Swift 3.0 support implemented
2 parents 473d469 + c0bbcf5 commit 62bce31

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1233
-1486
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
language: objective-c
2-
osx_image: xcode7.3
2+
osx_image: xcode8
33
xcode_project: RxBluetoothKit.xcodeproj
44
xcode_scheme: RxBluetoothKit
55
# RxSwift times out on travis with carthage version higher than 0.14
@@ -11,5 +11,5 @@ before_script:
1111
- carthage checkout --no-use-binaries
1212
- travis_retry carthage build --platform iOS
1313
script:
14-
- set -o pipefail && xcodebuild test -project RxBluetoothKit.xcodeproj -scheme "RxBluetoothKit iOS" -sdk iphonesimulator ONLY_ACTIVE_ARCH=NO | xcpretty
14+
- set -o pipefail && xcodebuild test -project RxBluetoothKit.xcodeproj -scheme "RxBluetoothKit iOS" -sdk iphonesimulator10.0 -destination "platform=iOS Simulator,OS=10.0,name=iPhone 7 Plus" ONLY_ACTIVE_ARCH=NO | xcpretty
1515

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
# 2.0.1
2-
- Changed RxSwift dependency from 2.6 to 2.6.0
1+
# 3.0.0
2+
- Implemented compatibility for Swift 3.0. This includes adoption of Swift Design Guidelines and new Value Types in Cocoa.
3+
- Implemented function `maximumWriteValueLength` on `Peripheral` instance that is available from OSX 10.12 and iOS 9.0
4+
- Couple of minor code cleanups in order to make source more concise and easier to read
35

46
# 2.0.0
57
- Implemented compatibility for Swift 2.3. This version is supposed to work with Xcode 7.3 and Xcode 8.

Cartfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
github "ReactiveX/RxSwift" == 2.6.0
1+
github "ReactiveX/RxSwift" "3.0.0-beta.1"

Cartfile.private

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
github "Quick/Nimble"
2-
github "Quick/Quick"
1+
github "Quick/Nimble" "v5.0.0"
2+
github "Quick/Quick" "v0.10.0"

Cartfile.resolved

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
github "Quick/Nimble" "v4.1.0"
2-
github "Quick/Quick" "v0.9.3"
3-
github "ReactiveX/RxSwift" "2.6.0"
1+
github "Quick/Nimble" "v5.0.0"
2+
github "Quick/Quick" "v0.10.0"
3+
github "ReactiveX/RxSwift" "3.0.0-beta.1"

Example/Example.xcodeproj/project.pbxproj

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,12 @@
153153
isa = PBXNativeTarget;
154154
buildConfigurationList = A1299C731CBE41C5005DEA5B /* Build configuration list for PBXNativeTarget "Example" */;
155155
buildPhases = (
156-
5BB20924261D292D6C4DE28A /* 📦 Check Pods Manifest.lock */,
156+
5BB20924261D292D6C4DE28A /* [CP] Check Pods Manifest.lock */,
157157
A1299C5D1CBE41C5005DEA5B /* Sources */,
158158
A1299C5E1CBE41C5005DEA5B /* Frameworks */,
159159
A1299C5F1CBE41C5005DEA5B /* Resources */,
160-
730B705F4CA266AAC95C979C /* 📦 Embed Pods Frameworks */,
161-
3EC3D9D318570A4E6B25F318 /* 📦 Copy Pods Resources */,
160+
730B705F4CA266AAC95C979C /* [CP] Embed Pods Frameworks */,
161+
3EC3D9D318570A4E6B25F318 /* [CP] Copy Pods Resources */,
162162
);
163163
buildRules = (
164164
);
@@ -176,7 +176,7 @@
176176
isa = PBXProject;
177177
attributes = {
178178
LastSwiftUpdateCheck = 0730;
179-
LastUpgradeCheck = 0730;
179+
LastUpgradeCheck = 0800;
180180
ORGANIZATIONNAME = Polidea;
181181
TargetAttributes = {
182182
A1299C601CBE41C5005DEA5B = {
@@ -216,44 +216,44 @@
216216
/* End PBXResourcesBuildPhase section */
217217

218218
/* Begin PBXShellScriptBuildPhase section */
219-
3EC3D9D318570A4E6B25F318 /* 📦 Copy Pods Resources */ = {
219+
3EC3D9D318570A4E6B25F318 /* [CP] Copy Pods Resources */ = {
220220
isa = PBXShellScriptBuildPhase;
221221
buildActionMask = 2147483647;
222222
files = (
223223
);
224224
inputPaths = (
225225
);
226-
name = "📦 Copy Pods Resources";
226+
name = "[CP] Copy Pods Resources";
227227
outputPaths = (
228228
);
229229
runOnlyForDeploymentPostprocessing = 0;
230230
shellPath = /bin/sh;
231231
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-Example/Pods-Example-resources.sh\"\n";
232232
showEnvVarsInLog = 0;
233233
};
234-
5BB20924261D292D6C4DE28A /* 📦 Check Pods Manifest.lock */ = {
234+
5BB20924261D292D6C4DE28A /* [CP] Check Pods Manifest.lock */ = {
235235
isa = PBXShellScriptBuildPhase;
236236
buildActionMask = 2147483647;
237237
files = (
238238
);
239239
inputPaths = (
240240
);
241-
name = "📦 Check Pods Manifest.lock";
241+
name = "[CP] Check Pods Manifest.lock";
242242
outputPaths = (
243243
);
244244
runOnlyForDeploymentPostprocessing = 0;
245245
shellPath = /bin/sh;
246246
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
247247
showEnvVarsInLog = 0;
248248
};
249-
730B705F4CA266AAC95C979C /* 📦 Embed Pods Frameworks */ = {
249+
730B705F4CA266AAC95C979C /* [CP] Embed Pods Frameworks */ = {
250250
isa = PBXShellScriptBuildPhase;
251251
buildActionMask = 2147483647;
252252
files = (
253253
);
254254
inputPaths = (
255255
);
256-
name = "📦 Embed Pods Frameworks";
256+
name = "[CP] Embed Pods Frameworks";
257257
outputPaths = (
258258
);
259259
runOnlyForDeploymentPostprocessing = 0;
@@ -307,8 +307,10 @@
307307
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
308308
CLANG_WARN_EMPTY_BODY = YES;
309309
CLANG_WARN_ENUM_CONVERSION = YES;
310+
CLANG_WARN_INFINITE_RECURSION = YES;
310311
CLANG_WARN_INT_CONVERSION = YES;
311312
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
313+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
312314
CLANG_WARN_UNREACHABLE_CODE = YES;
313315
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
314316
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -352,8 +354,10 @@
352354
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
353355
CLANG_WARN_EMPTY_BODY = YES;
354356
CLANG_WARN_ENUM_CONVERSION = YES;
357+
CLANG_WARN_INFINITE_RECURSION = YES;
355358
CLANG_WARN_INT_CONVERSION = YES;
356359
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
360+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
357361
CLANG_WARN_UNREACHABLE_CODE = YES;
358362
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
359363
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -372,6 +376,7 @@
372376
IPHONEOS_DEPLOYMENT_TARGET = 9.3;
373377
MTL_ENABLE_DEBUG_INFO = NO;
374378
SDKROOT = iphoneos;
379+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
375380
VALIDATE_PRODUCT = YES;
376381
};
377382
name = Release;
@@ -380,26 +385,30 @@
380385
isa = XCBuildConfiguration;
381386
baseConfigurationReference = 0E1242568DC6EBC77A838532 /* Pods-Example.debug.xcconfig */;
382387
buildSettings = {
388+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
383389
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
384390
CLANG_ENABLE_MODULES = YES;
385391
INFOPLIST_FILE = Example/Info.plist;
386392
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
387393
PRODUCT_BUNDLE_IDENTIFIER = com.polidea.Example;
388394
PRODUCT_NAME = "$(TARGET_NAME)";
389395
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
396+
SWIFT_VERSION = 3.0;
390397
};
391398
name = Debug;
392399
};
393400
A1299C751CBE41C5005DEA5B /* Release */ = {
394401
isa = XCBuildConfiguration;
395402
baseConfigurationReference = B4DAF7B5098A22F12280CB22 /* Pods-Example.release.xcconfig */;
396403
buildSettings = {
404+
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
397405
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
398406
CLANG_ENABLE_MODULES = YES;
399407
INFOPLIST_FILE = Example/Info.plist;
400408
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
401409
PRODUCT_BUNDLE_IDENTIFIER = com.polidea.Example;
402410
PRODUCT_NAME = "$(TARGET_NAME)";
411+
SWIFT_VERSION = 3.0;
403412
};
404413
name = Release;
405414
};

Example/Example.xcodeproj/xcshareddata/xcschemes/Example.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "0730"
3+
LastUpgradeVersion = "0800"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

Example/Example/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
16+
private func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
1717
// Override point for customization after application launch.
1818
return true
1919
}

Example/Example/CharacteristicsController.swift

Lines changed: 36 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class CharacteristicsController: UIViewController {
1818

1919
@IBOutlet weak var characteristicsTableView: UITableView!
2020

21-
private var characteristicsList: [Characteristic] = []
22-
private let characteristicCellId = "CharacteristicCell"
21+
fileprivate var characteristicsList: [Characteristic] = []
22+
fileprivate let characteristicCellId = "CharacteristicCell"
2323

2424
override func viewDidLoad() {
2525
super.viewDidLoad()
@@ -29,100 +29,96 @@ class CharacteristicsController: UIViewController {
2929
characteristicsTableView.rowHeight = UITableViewAutomaticDimension
3030
}
3131

32-
override func viewWillAppear(animated: Bool) {
32+
override func viewWillAppear(_ animated: Bool) {
3333
super.viewWillAppear(animated)
34-
getCharacteristicsForService(service)
34+
getCharacteristics(for: service)
3535
}
3636

37-
private func getCharacteristicsForService(service: Service) {
37+
private func getCharacteristics(for service: Service) {
3838
service.discoverCharacteristics(nil)
39-
.subscribeNext { characteristics in
39+
.subscribe(onNext: { characteristics in
4040
self.characteristicsList = characteristics
4141
self.characteristicsTableView.reloadData()
42-
}.addDisposableTo(disposeBag)
42+
}).addDisposableTo(disposeBag)
4343
}
4444

45-
private func setNotificationsState(enabled enabled: Bool, characteristic: Characteristic) {
45+
fileprivate func setNotificationsState(enabled: Bool, characteristic: Characteristic) {
4646
characteristic.setNotifyValue(enabled)
47-
.subscribeNext {
48-
self.refreshCharacteristic($0)
49-
}.addDisposableTo(disposeBag)
47+
.subscribe(onNext: { [weak self] _ in
48+
self?.characteristicsTableView.reloadData()
49+
}).addDisposableTo(disposeBag)
5050
}
5151

5252
private func showWriteFieldForCharacteristic(characteristic: Characteristic) {
5353
let valueWriteController = UIAlertController(title: "Write value", message: "Specify value in HEX to write ",
54-
preferredStyle: .Alert)
55-
valueWriteController.addTextFieldWithConfigurationHandler { textField in
54+
preferredStyle: .alert)
55+
valueWriteController.addTextField { textField in
5656

5757
}
58-
valueWriteController.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
59-
valueWriteController.addAction(UIAlertAction(title: "Write", style: .Default) { _ in
58+
valueWriteController.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
59+
valueWriteController.addAction(UIAlertAction(title: "Write", style: .default) { _ in
6060
print("")
6161
})
6262
}
6363

64-
private func triggerValueReadForCharacteristic(characteristic: Characteristic) {
64+
fileprivate func triggerValueRead(for characteristic: Characteristic) {
6565
characteristic.readValue()
66-
.subscribeNext {
67-
self.refreshCharacteristic($0)
68-
}.addDisposableTo(disposeBag)
69-
}
70-
71-
private func refreshCharacteristic(characteristic: Characteristic) {
72-
characteristicsTableView.reloadData()
66+
.subscribe(onNext: { [weak self] _ in
67+
self?.characteristicsTableView.reloadData()
68+
}).addDisposableTo(disposeBag)
7369
}
7470
}
7571

7672
extension CharacteristicsController: UITableViewDataSource, UITableViewDelegate {
7773

78-
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
74+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
7975
return characteristicsList.count
8076
}
8177

82-
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
83-
let cell = tableView.dequeueReusableCellWithIdentifier(characteristicCellId, forIndexPath: indexPath)
78+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
79+
let cell = tableView.dequeueReusableCell(withIdentifier: characteristicCellId, for: indexPath)
8480
let characteristic = characteristicsList[indexPath.row]
8581
if let cell = cell as? CharacteristicTableViewCell {
86-
cell.updateWithCharacteristic(characteristic)
82+
cell.update(with: characteristic)
8783
}
8884
return cell
8985
}
9086

91-
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
87+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
9288
let characteristic = characteristicsList[indexPath.row]
93-
let actionSheet = UIAlertController(title: "Choose action", message: nil, preferredStyle: .ActionSheet)
89+
let actionSheet = UIAlertController(title: "Choose action", message: nil, preferredStyle: .actionSheet)
9490

95-
if characteristic.properties.contains(.Notify) {
96-
let turnNotificationOffAction = UIAlertAction(title: "Turn OFF notifications", style: .Default) { _ in
91+
if characteristic.properties.contains(.notify) {
92+
let turnNotificationOffAction = UIAlertAction(title: "Turn OFF notifications", style: .default) { _ in
9793
self.setNotificationsState(enabled: false, characteristic: characteristic)
9894
}
99-
let turnNotificationOnAction = UIAlertAction(title: "Turn ON notifications", style: .Default) { _ in
95+
let turnNotificationOnAction = UIAlertAction(title: "Turn ON notifications", style: .default) { _ in
10096
self.setNotificationsState(enabled: true, characteristic: characteristic)
10197
}
10298
actionSheet.addAction(turnNotificationOffAction)
10399
actionSheet.addAction(turnNotificationOnAction)
104100
}
105-
if characteristic.properties.contains(.Read) {
106-
let readValueNotificationAction = UIAlertAction(title: "Trigger value read", style: .Default) { _ in
107-
self.triggerValueReadForCharacteristic(characteristic)
101+
if characteristic.properties.contains(.read) {
102+
let readValueNotificationAction = UIAlertAction(title: "Trigger value read", style: .default) { _ in
103+
self.triggerValueRead(for: characteristic)
108104
}
109105
actionSheet.addAction(readValueNotificationAction)
110106
}
111-
self.presentViewController(actionSheet, animated: true, completion: nil)
107+
self.present(actionSheet, animated: true, completion: nil)
112108
}
113109

114-
func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
110+
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
115111
return UIView(frame: .zero)
116112
}
117113

118-
func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
114+
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
119115
return "CHARACTERISTICS"
120116
}
121117
}
122118

123119
extension CharacteristicTableViewCell {
124-
func updateWithCharacteristic(characteristic: Characteristic) {
125-
self.UUIDLabel.text = characteristic.UUID.UUIDString
120+
func update(with characteristic: Characteristic) {
121+
self.UUIDLabel.text = characteristic.uuid.uuidString
126122
self.isNotifyingLabel.text = characteristic.isNotifying ? "true" : "false"
127123
self.valueLabel.text = characteristic.value?.hexadecimalString ?? "Empty"
128124
}

0 commit comments

Comments
 (0)