Firstly Hello Everyone - I am having a few issues with an app I am trying to do for my personal use (I have never done coding) I got Chat GPT to do the coding but it has a few issues, from what I can tell this is an issue with the Face ID part of it but I have no clue how to fix it, would someone please help
the issue says the following
"Cannot use mutating member on immutable value: 'self' is immutable"
Many Thanks
Tom
import SwiftUI
import LocalAuthentication
import SwiftUICore
import SwiftUI
struct SettingsView: View {
@State private var faceIDEnabled = false
@State private var isAuthenticated = false
var body: some View {
NavigationView {
Form {
Toggle("Enable Face ID Lock", isOn: $faceIDEnabled)
.onChange(of: faceIDEnabled) { value in
if value {
authenticate()
}
}
if isAuthenticated {
Text("Face ID authentication successful ✅")
.foregroundColor(.green)
}
}
.navigationTitle("Settings")
}
}
mutating func authenticate() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let reason = "Secure your job data with Face ID"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authError in
DispatchQueue.main.async {
self.isAuthenticated = success
if !success {
self.faceIDEnabled = false
}
}
}
} else {
self.faceIDEnabled = false
}
}
}