Ambiguous use of 'logOut()'

No matter how I try to go about logging out the Realm user, I’m getting the error “Ambiguous use of ‘logOut()’”. I’m making sure the type is RLMUser, I’ve imported SwiftUI, RealmSwift, and Realm, and I’ve triple checked that nothing else in my code is named logOut. Any help would be greatly appreciated. Here’s my code:

import SwiftUI
import RealmSwift
import Realm

struct LogOutButton: View {
    @State var logOutPromptIsPresented = false
    
    var body: some View {
        HStack {
            Spacer()
            Button {
                logOutPromptIsPresented = true
            } label: {
                Text("")
                    .bodyTextStyle(text: "Log out")
            }
        }
        .padding(20)
        .alert("Are you sure you want to log out?", isPresented: $logOutPromptIsPresented, actions: {
            Button(role: .destructive) {
                logUserOut()
            } label: {
                Text("Yes")
            }
            Button(role: .cancel) {
                logOutPromptIsPresented = false
            } label: {
                Text("No")
            }
        })
    }
    
    func logUserOut() {
        do {
            guard let user: RLMUser = app.currentUser else {
                return
            }
            try user.logOut() //this is the line where I'm getting the error
        } catch {
            print("Error logging out: \(error.localizedDescription)")
        }
    }
}

Try this

your_app.currentUser?.logOut { (error) in
   guard error == nil else {
      print("Logout failed: \(error!.localizedDescription)");
      return
    }

   print("Logged out!");
}

From

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.