Ich habe ein Code in Swift geschrieben und bekomme zwei Fehler wo ich nicht weiß wie ich sie beheben kann
Meine Dateien:
AppState:
import Foundation
class AppState: ObservableObject {
@Published var isLockedIn = false
}
ContentView:
import SwiftUI
import LocalAuthentication
struct LoginView: View {
@State private var unlocked = false
@State private var text = "Gespert"
@EnvironmentObject var appState = AppState()
var body: some View {
VStack {
Text(text)
.bold()
.padding()
Button("Entsperen") {
authenticate()
}
}
}
func authenticate() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: "Das ist zum entsperren der App") {
success, authenticatinError in
if success {
text = "ENTSPERT"
appState.isLockedIn = true
}else {
text = "ES GAB EIN PROBLEM"
}
}
}else {
text = "DAS GERET UNTERSTÜTZT KEINE BIOMETRIE"
}
}
}
struct ContentView: View {
var body: some View {
NavigationView {
List(0..<4) {
_ in
NavigationLink(destination: HabitDetail()) {
HabitItem()
}
}
.listStyle(InsetListStyle())
.navigationTitle("Habits")
}
}
}
struct HabitItem: View {
var body: some View {
VStack {
HStack {
Text("Habit")
Spacer()
}
}
}
}
struct HabitDetail: View {
@State private var isOn = false
var body: some View {
VStack {
HStack {
Spacer()
EditButton()
.padding(10)
NavigationLink(destination: HabitCalender()) {
Image(systemName: "calendar")
.padding(10)
}
}
}
ScrollView {
HStack{
Text("Aufgabe:")
.padding(10)
Spacer()
Text("")
.padding(10)
}
HStack{
Text("Beschreibung:")
.padding(10)
Spacer()
Text("")
}
HStack {
Text("Erledigt ?")
.padding(10)
Spacer()
Toggle(isOn: $isOn) {
Text("")
}
.toggleStyle(iOSCheckboxToggleStyle())
.padding(10)
}
HStack{
Text("5 Tage übersicht:")
.padding(10)
Image(systemName: "square")
Image(systemName: "square")
Image(systemName: "square")
Image(systemName: "square")
Image(systemName: "square")
Image(systemName: "square")
Image(systemName: "square")
Spacer()
}
VStack {
ProgressView(value: 0.5)
.padding(10)
HStack {
Text("Serie:")
.padding(10)
Spacer()
HStack {
Text("30")
Text("/ 60")
}
.padding(10)
}
}
}
}
}
struct HabitCalender: View {
var body: some View {
Text("Kommt Bald")
}
}
struct iOSCheckboxToggleStyle: ToggleStyle {
func makeBody(configuration: Configuration) -> some View {
// 1
Button(action: {
// 2
configuration.isOn.toggle()
}, label: {
HStack {
// 3
Image(systemName: configuration.isOn ? "checkmark.square" : "square")
configuration.label
}
})
}
}
// MARK: - Preview
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
LoginView()
}
}
MyApp:
import SwiftUI
@main
struct MyApp: App {
@StateObject private var appState = AppState()
var body: some Scene {
WindowGroup {
if !appState.isLockedIn {
LoginView()
.environmentObject(appState)
}else {
ContentView()
}
}
}
}
Die Fehler sind :
Argument passed to call that takes no argument
Und
Generic parameter ˋObjectType ´ could not inferred
Ich habe keine Ahnung was man probieren kann da ich relativ neu bei Swift bin
New contributor
Jamie Braune is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.