解決方案來源:
swift 对日期的处理大全
var Date1: Date = Date() var Date2: Date = Date() let nInterval = Date2.timeIntervalSince(Date1)
var Date1: Date = Date() var Date2: Date = Date() let nInterval = Date2.timeIntervalSince(Date1)
class TBleDeviceConnect: NSObject, CBCentralManagerDelegate, BPeripheralDelegate { var centralManager: CBCentralManager! = nil func centralManagerInit() { centralManager = CBCentralManager.init(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true]) } }
class MainViewController: UIViewController { /* Class Bluetooth CBCentralManager Control */ var BleDeviceConnect: TBleDeviceConnect! = nil }
DispatchQueue.main.async { self.BleDeviceConnect.centralManagerInit() }
class MainViewController: UIViewController { /* Class Bluetooth CBCentralManager Control */ var BleConnectDevice: TBleDeviceConnect! = nil override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if( segue.identifier == "SegueOptions") { let destinationNavigationController = segue.destination as! UINavigationController let OptionsVc = destinationNavigationController.topViewController as! OptionsTableViewController OptionsVc.BleScannerDevice = self.BleScannerDevice } } }
class OptionsTableViewController: UITableViewController, UITextFieldDelegate { var BleScannerDevice: TBlueScannerDevice! = nil @IBAction func BtnBleOnClick(_ sender: Any) { DispatchQueue.main.async { self.BleScannerDevice.CentralManagerInit() } } }
class TBleDeviceConnect: NSObject, CBCentralManagerDelegate, CBPeripheralDelegate { var cCentralManager: CBCentralManager! = nil func CentralManagerInit() { cCentralManager = CBCentralManager.init(delegate: self, queue: nil, options: [CBCentralManagerOptionShowPowerAlertKey: true]) } }