程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了线程 1:致命错误:找不到 SessionStore 类型的 ObservableObject大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决线程 1:致命错误:找不到 SessionStore 类型的 ObservabLeobject?

开发过程中遇到线程 1:致命错误:找不到 SessionStore 类型的 ObservabLeobject的问题如何解决?下面主要结合日常开发的经验,给出你关于线程 1:致命错误:找不到 SessionStore 类型的 ObservabLeobject的解决方法建议,希望对你解决线程 1:致命错误:找不到 SessionStore 类型的 ObservabLeobject有所启发或帮助;

我收到以下错误消息:线程 1:致命错误:未找到类型为 SessionStore 的 ObservabLeobject。 SessionStore 的 VIEw.environmentObject(_:) 可能缺少作为此视图的祖先。

致命错误:未找到类型为 SessionStore 的 ObservabLeobject。 SessionStore 的 VIEw.environmentObject(_:) 作为此视图的祖先可能会丢失。:文件 SwiftUI,第 0 行

但我已经将 environmentObject(SessionStore()) 添加到预览中。所以我不明白为什么会这样。

这是我的 ContentVIEw 文件:

    import SwiftUI
import Firebase
import linkKit

struct ContentVIEw: VIEw {
    
    func getUser() {
        session.Listen()
    }
    @State private var showingSheet = true
    
    @EnvironmentObject var session: SessionStore
    @StateObject private var manager = FirebaseManager()
    
    
    var body: some VIEw {
        Group {
            if (session.session != nil && manager.profilePicExists == truE) {
                HosTingTabVIEw()
            } else if (session.session != nil && manager.profilePicExists == falsE){
                HosTingTabVIEw().sheet(isPresented: $showingSheet) {
                    RegistrationProfileDataVIEw()
                }
            } else {
                AuthVIEw()
           }
        }.onAppear(perform: getUser)
        .onAppear(perform: manager.checkForProfileImagE)
    }
}

struct ContentVIEw_PrevIEws: PrevIEwProvIDer {
    static var prevIEws: some VIEw {
        ContentVIEw().environmentObject(SessionStore())
    }
}

这是 SessionStore 文件文件:

import SwiftUI
import Firebase
import Combine

class SessionStore: ObservabLeobject {
     var dIDChange =  PassthroughSubject<SessionStore,Never>()
    @Published var session: User? {dIDSet {self.dIDChange.send(self) }}
    var handle: AuthStateDIDchangelistenerHandle?
    
    func Listen() {
        handle = Auth.auth().addStateDIDchangelistener({ (auth,user) in
            if let user = user {
                self.session = User(uID: user.uID,email: user.email)
            } else {
                self.session = nil
            }
        })
    }
    
    func signUp(email: String,password: String,handler: @escaPing AuthDataResultCallBACk) {
        Auth.auth().createuser(withEmail: email,password: password,completion: handler)
    }
    
    func signIn(email: String,handler: @escaPing AuthDataResultCallBACk) {
        Auth.auth().signIn(withEmail: email,completion: handler)
    }
    
    func signOut() {
        do {
            try Auth.auth().signOut()
            self.session = nil
        } catch {
            print("Error signing out")
        }
    }
    
    func unbind() {
        if let handle = handle {
            Auth.auth().removeStateDIDchangelistener(handlE)
        }
    }
    
    deinit {
        unbind()
    }
    
}

struct User {
    var uID: String
    var email: String?
    
    init(uID: String,email: String?) {
        self.uID = uID
        self.email = email
    }
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

大佬总结

以上是大佬教程为你收集整理的线程 1:致命错误:找不到 SessionStore 类型的 ObservableObject全部内容,希望文章能够帮你解决线程 1:致命错误:找不到 SessionStore 类型的 ObservableObject所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。