Hi,
Because the xcode simulator does not work with bluetooth I noticed that a destination view @State variable gets called before clicking:
In this settings view there a section for Bluetooth.
struct SettingsView: View {
@State private var viewModel = SettingsViewModel()
var body: some View {
NavigationStack {
List {
//
//
//
Section("Bluetooth Low Energy") {
NavigationLink (destination: BleModulesView()) {
HStack {
Image(systemName: "iphone.gen2.radiowaves.left.and.right")
.symbolRenderingMode(.palette)
.foregroundStyle(.primary, .teal)
.font(.system(size:30))
Text("Read and/or change parameters when module is nearby")
.frame(maxWidth: .infinity ,alignment: .leading)
.padding(4)
}
}
.font(.subheadline)
}
.headerProminence(.increased)
//
//
...
When I click on that item, it opens a new view (the destination):
import SwiftUI
struct BleModulesView: View {
@State private var bluetoothScanner = BluetoothScanner()
var body: some View {
It all works fine, BUT:
I noticed, via the errors in the simulator, that as soon as I open the SettingsView the BluetoothScanner from BleModulesView gets called?
Why?
Why does it gets called before being clicked (and displayed)?
Korstiaan