@@ -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 {
4343extension 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
9090extension 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
144144extension 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
152152extension 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}
0 commit comments