Skip to content

Commit c4ac005

Browse files
committed
migrated to swift 4
1 parent f7ce00c commit c4ac005

20 files changed

Lines changed: 414 additions & 390 deletions

Example/Podfile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
source 'https://github.com/CocoaPods/Specs.git'
22
use_frameworks!
33

4-
target 'RFDuino_Example', :exclusive => true do
4+
target 'RFDuino_Example' do
55
pod 'RFDuino', :path => '../'
66
end
77

8-
target 'RBLNano-Example', :exclusive => true do
8+
target 'RBLNano-Example' do
99
pod 'RFDuino', :path => '../'
1010
end
1111

12-
target 'RFDuino_Tests', :exclusive => true do
12+
target 'RFDuino_Tests' do
1313
pod 'RFDuino', :path => '../'
14-
14+
1515
end

Example/Podfile.lock

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PODS:
2-
- RFDuino (0.1.1)
2+
- RFDuino (0.2.1)
33

44
DEPENDENCIES:
55
- RFDuino (from `../`)
@@ -9,6 +9,8 @@ EXTERNAL SOURCES:
99
:path: ../
1010

1111
SPEC CHECKSUMS:
12-
RFDuino: 827787064d06aaef58ff082b3bde12592c05b8c2
12+
RFDuino: 9e5bb8f89ad28495f8da2f519cec6c2ec8127706
1313

14-
COCOAPODS: 0.39.0
14+
PODFILE CHECKSUM: ff820f9196a6c560e5b1d4ca84b137ae756d07a3
15+
16+
COCOAPODS: 1.3.1

Example/RBLNano-Example/Base.lproj/LaunchScreen.storyboard

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="9532" systemVersion="15D21" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" initialViewController="01J-lp-oVM">
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="13771" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" launchScreen="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="01J-lp-oVM">
3+
<device id="retina4_7" orientation="portrait">
4+
<adaptation id="fullscreen"/>
5+
</device>
36
<dependencies>
47
<deployment identifier="iOS"/>
5-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="9530"/>
8+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="13772"/>
69
<capability name="Constraints to layout margins" minToolsVersion="6.0"/>
10+
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
711
</dependencies>
812
<scenes>
913
<!--View Controller-->
@@ -15,24 +19,24 @@
1519
<viewControllerLayoutGuide type="bottom" id="xb3-aO-Qok"/>
1620
</layoutGuides>
1721
<view key="view" contentMode="scaleToFill" id="Ze5-6b-2t3">
18-
<rect key="frame" x="0.0" y="0.0" width="600" height="600"/>
22+
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
1923
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
2024
<subviews>
2125
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Red Bear Lab BLE Nano Demo" textAlignment="center" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" minimumScaleFactor="0.5" translatesAutoresizingMaskIntoConstraints="NO" id="xuH-xI-xeU">
22-
<rect key="frame" x="20" y="284" width="560" height="33"/>
26+
<rect key="frame" x="16" y="318" width="343" height="31.5"/>
2327
<fontDescription key="fontDescription" style="UICTFontTextStyleTitle1"/>
24-
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="calibratedRGB"/>
28+
<color key="textColor" red="0.0" green="0.0" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
2529
<nil key="highlightedColor"/>
2630
</label>
2731
<imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" image="soldered" translatesAutoresizingMaskIntoConstraints="NO" id="ZHu-Sp-jvH">
28-
<rect key="frame" x="180" y="158" width="240" height="128"/>
32+
<rect key="frame" x="67.5" y="191.5" width="240" height="128"/>
2933
<constraints>
3034
<constraint firstAttribute="width" constant="240" id="3FT-fv-X1R"/>
3135
<constraint firstAttribute="height" constant="128" id="5Ru-pg-457"/>
3236
</constraints>
3337
</imageView>
3438
</subviews>
35-
<color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="calibratedWhite"/>
39+
<color key="backgroundColor" red="1" green="1" blue="1" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
3640
<constraints>
3741
<constraint firstItem="ZHu-Sp-jvH" firstAttribute="centerX" secondItem="Ze5-6b-2t3" secondAttribute="centerX" id="24P-Sx-GPh"/>
3842
<constraint firstItem="xuH-xI-xeU" firstAttribute="leading" secondItem="Ze5-6b-2t3" secondAttribute="leadingMargin" id="BxS-1B-0JS"/>

Example/RBLNano-Example/DetailsViewController.swift

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ class DetailsViewController: UIViewController {
3333
manager.delegate = self
3434
titleLabel.text = rfDuino?.name
3535

36-
bluetoothLogo.setImageTintColor(UIColor.blackColor())
37-
manager.setLoggingEnabled(true)
36+
bluetoothLogo.setImageTintColor(color: UIColor.black)
37+
manager.setLoggingEnabled(enabled: true)
3838

3939
navigationItem.title = "RBL Nano devive"
4040
}
@@ -43,33 +43,33 @@ class DetailsViewController: UIViewController {
4343
extension DetailsViewController {
4444

4545
@IBAction func connect(sender: UIButton) {
46-
statusLabel.text = "connecting".uppercaseString
47-
manager.connectRFDuino(rfDuino!)
46+
statusLabel.text = "connecting".uppercased()
47+
manager.connectRFDuino(rfDuino: rfDuino!)
4848
}
4949

5050
@IBAction func disconnect(sender: AnyObject) {
51-
statusLabel.text = "disconnecting".uppercaseString
51+
statusLabel.text = "disconnecting".uppercased()
5252
if rfDuino!.isConnected {
53-
manager.disconnectRFDuinoWithoutSendCommand(rfDuino!)
53+
manager.disconnectRFDuinoWithoutSendCommand(rfDuino: rfDuino!)
5454
} else {
5555
statusLabel.text = (rfDuino?.name ?? "rfDuino") + " not connected..."
56-
statusLabel.delay(1.0, closure: { () -> () in
57-
self.statusLabel.text = "idle".uppercaseString
56+
statusLabel.delay(time: 1.0, closure: { () -> () in
57+
self.statusLabel.text = "idle".uppercased()
5858
})
5959
}
6060
}
6161

6262
@IBAction func discoverServices(sender: AnyObject) {
63-
statusLabel.text = "discovering services".uppercaseString
63+
statusLabel.text = "discovering services".uppercased()
6464
if rfDuino!.isConnected {
6565
rfDuino!.discoverServices()
6666
}
6767
}
6868

6969
@IBAction func sendData(sender: UIButton) {
70-
statusLabel.text = "sending data".uppercaseString
70+
statusLabel.text = "sending data".uppercased()
7171
if rfDuino!.isConnected {
72-
rfDuino!.send(String("hello").dataUsingEncoding(NSASCIIStringEncoding)!)
72+
rfDuino!.send(data: String("hello").data(using: String.Encoding.ascii)!)
7373
}
7474
}
7575
}
@@ -80,82 +80,78 @@ extension DetailsViewController: RFDuinoBTManagerDelegate {
8080
}
8181

8282
func rfDuinoManagerDidConnectRFDuino(manager: RFDuinoBTManager, rfDuino: RFDuino) {
83-
statusLabel.text = "idle".uppercaseString
84-
bluetoothLogo.setImageTintColor(UIColor.greenColor())
85-
connectButton.enabled = false
86-
disconnectButton.enabled = true
83+
statusLabel.text = "idle".uppercased()
84+
bluetoothLogo.setImageTintColor(color: UIColor.green)
85+
connectButton.isEnabled = false
86+
disconnectButton.isEnabled = true
8787
}
8888
}
8989

9090
extension DetailsViewController: RFDuinoDelegate {
9191

9292
func rfDuinoDidDiscoverCharacteristics(rfDuino: RFDuino) {
93-
bluetoothLogo.setImageTintColor(bluetoothColor)
94-
statusLabel.text = "idle".uppercaseString
95-
discoverButton.enabled = false
93+
bluetoothLogo.setImageTintColor(color: bluetoothColor)
94+
statusLabel.text = "idle".uppercased()
95+
discoverButton.isEnabled = false
9696
}
9797

9898
func rfDuinoDidDiscoverServices(rfDuino: RFDuino) {
99-
bluetoothLogo.setImageTintColor(UIColor.blueColor())
100-
statusLabel.text = "idle".uppercaseString
99+
bluetoothLogo.setImageTintColor(color: UIColor.blue)
100+
statusLabel.text = "idle".uppercased()
101101
}
102102

103-
func rfDuinoDidSendData(rfDuino: RFDuino, forCharacteristic: CBCharacteristic, error: NSError?) {
103+
func rfDuinoDidSendData(rfDuino: RFDuino, forCharacteristic: CBCharacteristic, error: Error?) {
104104
if isAnimating {
105105
return
106106
}
107107
isAnimating = true
108-
dispatch_async(dispatch_get_main_queue()) { () -> Void in
109-
self.bluetoothLogo.layer.backgroundColor = UIColor.whiteColor().CGColor
108+
DispatchQueue.main.async {
109+
self.bluetoothLogo.layer.backgroundColor = UIColor.white.cgColor
110110
self.bluetoothLogo.layer.cornerRadius = self.bluetoothLogo.frame.size.width / 2
111-
UIView.animateWithDuration(0.3, animations: { () -> Void in
112-
self.bluetoothLogo.layer.backgroundColor = self.bluetoothColor.colorWithAlphaComponent(0.2).CGColor
113-
}) { (bool) -> Void in
111+
UIView.animate(withDuration: 0.3, animations: { () -> Void in
112+
self.bluetoothLogo.layer.backgroundColor = self.bluetoothColor.withAlphaComponent(0.2).cgColor
113+
}) { (bool) -> Void in
114114
self.isAnimating = false
115-
self.bluetoothLogo.layer.backgroundColor = UIColor.whiteColor().CGColor
116-
self.statusLabel.text = "idle".uppercaseString
115+
self.bluetoothLogo.layer.backgroundColor = UIColor.white.cgColor
116+
self.statusLabel.text = "idle".uppercased()
117117
}
118118
}
119119
}
120120

121121
func rfDuinoDidTimeout(rfDuino: RFDuino) {
122-
bluetoothLogo.setImageTintColor(UIColor.redColor())
123-
statusLabel.text = "idle".uppercaseString
122+
bluetoothLogo.setImageTintColor(color: UIColor.red)
123+
statusLabel.text = "idle".uppercased()
124124
}
125125

126126
func rfDuinoDidDiscover(rfDuino: RFDuino) {
127-
bluetoothLogo.setImageTintColor(UIColor.blackColor())
128-
statusLabel.text = "idle".uppercaseString
127+
bluetoothLogo.setImageTintColor(color: UIColor.black)
128+
statusLabel.text = "idle".uppercased()
129129
}
130130

131131
func rfDuinoDidDisconnect(rfDuino: RFDuino) {
132-
connectButton.enabled = true
133-
disconnectButton.enabled = false
134-
discoverButton.enabled = true
135-
statusLabel.text = "idle".uppercaseString
136-
bluetoothLogo.setImageTintColor(UIColor.blackColor())
132+
connectButton.isEnabled = true
133+
disconnectButton.isEnabled = false
134+
discoverButton.isEnabled = true
135+
statusLabel.text = "idle".uppercased()
136+
bluetoothLogo.setImageTintColor(color: UIColor.black)
137137
}
138138

139-
func rfDuinoDidReceiveData(rfDuino: RFDuino, data: NSData?) {
139+
func rfDuinoDidReceiveData(rfDuino: RFDuino, data: Data?) {
140140
print("rfDuino did receive data")
141141
}
142142
}
143143

144144
extension UIImageView {
145145
func setImageTintColor(color: UIColor) {
146-
let image = self.image?.imageWithRenderingMode(.AlwaysTemplate)
146+
let image = self.image?.withRenderingMode(.alwaysTemplate)
147147
self.image = image
148148
self.tintColor = color
149149
}
150150
}
151151

152152
extension UILabel {
153-
func delay(time: Double, closure:()->()) {
154-
dispatch_after(
155-
dispatch_time(
156-
DISPATCH_TIME_NOW,
157-
Int64(time * Double(NSEC_PER_SEC))
158-
),
159-
dispatch_get_main_queue(), closure)
153+
func delay(time: Double, closure: @escaping ()->()) {
154+
let dt = DispatchTime(uptimeNanoseconds: UInt64(time))
155+
DispatchQueue.main.asyncAfter(deadline: dt, execute: closure)
160156
}
161157
}

Example/RBLNano-Example/DiscoveryTableViewController.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,54 +29,53 @@ class DiscoveryTableViewController: UITableViewController {
2929
navigationItem.title = "RBL Nano devices"
3030

3131
manager.startScanningForRFDuinos()
32-
manager.setLoggingEnabled(true)
32+
manager.setLoggingEnabled(enabled: true)
3333
tableView.rowHeight = 56
3434
tableView.tableFooterView = UIView()
3535
}
3636

37-
override func viewDidDisappear(animated: Bool) {
37+
override func viewDidDisappear(_ animated: Bool) {
3838
super.viewDidAppear(animated)
3939
if let selectedIP = tableView.indexPathForSelectedRow {
40-
tableView.deselectRowAtIndexPath(selectedIP, animated: true)
40+
tableView.deselectRow(at: selectedIP, animated: true)
4141
}
4242
}
4343

44-
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
44+
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
4545
return max(manager.discoveredRFDuinos.count, 1)
4646
}
4747

48-
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
49-
48+
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
5049
if manager.discoveredRFDuinos.count == 0 {
51-
return tableView.dequeueReusableCellWithIdentifier("noResultsCell")!
50+
return tableView.dequeueReusableCell(withIdentifier: "noResultsCell")!
5251
}
5352

5453
let identifier = "rfDuinoCell"
5554
let rfDuino = manager.discoveredRFDuinos[indexPath.row]
56-
let cell = tableView.dequeueReusableCellWithIdentifier(identifier)
55+
let cell = tableView.dequeueReusableCell(withIdentifier: identifier)
5756

5857
if rfDuino.isTimedOut {
59-
cell?.textLabel?.textColor = UIColor.grayColor()
58+
cell?.textLabel?.textColor = UIColor.gray
6059
cell?.textLabel?.text = rfDuino.name + " (timed out)"
6160
} else {
62-
cell?.textLabel?.textColor = UIColor.blackColor()
61+
cell?.textLabel?.textColor = UIColor.black
6362
cell?.textLabel?.text = rfDuino.name + (rfDuino.RSSI != nil ? " \(rfDuino.RSSI!)" : "")
6463
}
6564

6665
return cell!
6766
}
6867

69-
override func shouldPerformSegueWithIdentifier(identifier: String, sender: AnyObject?) -> Bool {
68+
override func shouldPerformSegue(withIdentifier identifier: String, sender: Any?) -> Bool {
7069
let rfDuino = manager.discoveredRFDuinos[tableView.indexPathForSelectedRow!.row]
7170
if rfDuino.isTimedOut {
72-
tableView.deselectRowAtIndexPath(tableView.indexPathForSelectedRow!, animated: true)
71+
tableView.deselectRow(at: tableView.indexPathForSelectedRow!, animated: true)
7372
}
7473
return !rfDuino.isTimedOut
7574
}
7675

77-
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
76+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
7877
let rfDuino = manager.discoveredRFDuinos[tableView.indexPathForSelectedRow!.row]
79-
let d = segue.destinationViewController as? DetailsViewController
78+
let d = segue.destination as? DetailsViewController
8079
d?.rfDuino = rfDuino
8180
}
8281
}
@@ -96,4 +95,4 @@ extension DiscoveryTableViewController: RFDuinoDelegate {
9695
func rfDuinoDidDiscover(rfDuino: RFDuino) {
9796
tableView.reloadData()
9897
}
99-
}
98+
}

Example/RBLNano-Example/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
18-
<string>1.0</string>
18+
<string>1.1</string>
1919
<key>CFBundleSignature</key>
2020
<string>????</string>
2121
<key>CFBundleVersion</key>

0 commit comments

Comments
 (0)