我目前正在尝试构建一个可以与 HM-18 BLE 模块通信的快速游乐场。
我是新来的。我只是没有得到委托的东西以及我需要在那里分配的对象(???)。
让我分解一行并解释我认为我理解的部分:
let managerDelegate: PlaygroundBluetoothCentralManagerDelegate = ???
Let 声明一个名称为 managerDelegate的常量,该常量必须是PlaygroundBluetoothCentralManagerDelegate 类型
我只是不知道=之后会发生什么
到目前为止,这是我的代码:
import CoreBluetooth
import PlaygroundBluetooth
import PlaygroundSupport
// Create State enum (shape)
enum Shape: String, CaseIterable {
case on, off
}
struct ContentView: View {
// Get all cases
let LEDStates = Shape.allCases
// State Variable (state binding observables -> learn)
@State private var selectedStateIndex = 0
// I dont get this part from: https://developer.apple.com/documentation/playgroundbluetooth/connecting_to_bluetooth_peripherals_in_swift_playgrounds
let managerDelegate: PlaygroundBluetoothCentralManagerDelegate = ???
let manager = PlaygroundBluetoothCentralManager(services: nil)
manager.delegate = managerDelegate
let viewDelegate: PlaygroundBluetoothConnectionViewDelegate = ???
let connectionView = PlaygroundBluetoothConnectionView(centralManager: manager, delegate: viewDelegate)
connectionView.dataSource = viewDelegate
// Place the connection view within the rest of your page's content.
let page: UIViewController & PlaygroundLiveViewSafeAreaContainer = ???
page.view.addSubview(connectionView)
// Position the connection view in the top right corner.
connectionView.topAnchor.constraint(equalTo: page.liveViewSafeAreaGuide.topAnchor, constant: 20).isActive = true
connectionView.trailingAnchor.constraint(equalTo: page.liveViewSafeAreaGuide.trailingAnchor, constant: -20).isActive = true
// This I understand
PlaygroundPage.current.liveView = page
var body: some View {
ZStack(alignment: .bottomTrailing) {
Picker("LED State", selection: $selectedStateIndex) {
ForEach(0..<LEDStates.count) { index in
Text(self.LEDStates[index].rawValue).tag(index)
}
}.pickerStyle(SegmentedPickerStyle())
.padding(10)
.background(Color.black.opacity(0.5))
}
}
}
PlaygroundPage.current.setLiveView(ContentView())