Quantcast
Channel: Biometric Authentication evaluation with swiftUI - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Answer by Aleksey Potapov for Biometric Authentication evaluation with swiftUI

$
0
0

Explanation:

'unowned' may only be applied to class and class-bound protocol types, not 'AuthenticateView'

First of all, you have AuthenticateView which is a struct. You can't do it class because whole Apple's SwiftUI idea is about structures. And because Struct is value type and not a Reference type, so no pointer as such. So you may not include code parts containing unowned self and weak self modifiers into struct AuthenticateView: View {}

Value of type 'AuthenticateView' has no member 'present'

present is a UIViewController's method. Here in SwiftUI you have no access to it. The alerts are being presented using the next style:

struct ContentView: View {    @State private var show = false    var body: some View {        Button(action: { self.show = true }) { Text("Click") }        .alert(isPresented: $showingAlert) {            Alert(title: Text("Title"),                 message: Text("Message"),           dismissButton: .default(Text("Close")))        }    }}

Solution:For your case, I would create a class Handler subclass of ObservableObject for your logic and use the power of @ObservedObject, @Published and @State.

Rough example for understanding the concept:

import SwiftUIstruct ContentView: View {    @ObservedObject var handler = Handler()    var body: some View {        Button(action: { self.handler.toggleShowAlert() }) { Text("Click") }            .alert(isPresented: $handler.shouldShowAlert) {                Alert(title: Text(handler.someTitle),                    message: Text(handler.someMessage),              dismissButton: .default(Text("Close")))        }    }}struct ContentView_Previews: PreviewProvider {    static var previews: some View {        ContentView()    }}class Handler: ObservableObject {    @Published var shouldShowAlert: Bool = false    @Published var someTitle = ""    @Published var someMessage = ""    func toggleShowAlert() {        shouldShowAlert.toggle()        someTitle = "ErrorTitle"        someMessage = "ErrorMessage"    }}

Viewing all articles
Browse latest Browse all 2

Trending Articles





<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>