Невозможно присвоить значение типа 'String?'набрать "CBPeripheral?" - PullRequest
0 голосов
/ 05 октября 2018
import UIKit
import CoreBluetooth

class ScaningViewController: UIViewController, CBCentralManagerDelegate, CBPeripheralDelegate {

var centralManager: CBCentralManager?
var peripheralDevice: CBPeripheral?
var devicesArray: [String] = []
var refreshControl = UIRefreshControl()

var selectedDevice: String?

@IBOutlet weak var DeviceListTableView: UITableView!

override func viewDidLoad() {
    super.viewDidLoad()
}

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return devicesArray.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? DeviceListTableViewCell
    cell?.deviceName.text = devicesArray[indexPath.item]
    return cell!
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    selectedDevice = devicesArray[indexPath.item]
    print(selectedDevice!)
    centralManager?.stopScan()
    self.decodePeripheralState(peripheralState: selectedDevice.state)
    self.peripheralDevice = selectedDevice
    self.peripheralDevice?.delegate = self
    print(self.peripheralDevice!)
    self.centralManager!.connect(self.peripheralDevice!)
    }

В методе func tableView (_ tableView: UITableView, didSelectRowAt indexPath: IndexPath), когда я выбираю строку, в это время я получаю indexpath.item в строке, но я хочу этот selectedDevice в типе CBPeripheral.Пожалуйста, дайте мне какое-нибудь решение для этого.Заранее спасибо ...

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...