快速打印数据库[重复]
Posted
技术标签:
【中文标题】快速打印数据库[重复]【英文标题】:Print DataBase in swift [duplicate] 【发布时间】:2021-03-27 12:16:58 【问题描述】:我做了一个应用程序的前端,但现在我必须做后端,因此打印一个数据库问题是我有一个错误“无法获取 FirebaseApp 实例。请在使用 Firestore 之前调用 FirebaseApp.configure() " :
应用委托:
class AppDelegate: NSObject, UIApplicationDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
FirebaseApp.configure()
return true
数据库:
struct New: Identifiable
var id: String = UUID().uuidString
var news: String
class NewsViewModel: ObservableObject
@Published var news = [New]()
private var db = Firestore.firestore()
func fetchDate()
db.collection("News").addSnapshotListener (querySnapshot, error) in
guard let documents = querySnapshot?.documents else
print("No documents")
return
self.news = documents.map (QueryDocumentSnapshot) -> New in
let data = QueryDocumentSnapshot.data()
let news = data["News"] as? String ?? "ya r"
return New(news: news)
打印数据库:
NavigationView
List(viewModel.news) news in
VStack(alignment: .leading)
Text(news.news)
.navigationTitle("News")
.onAppear()
self.viewModel.fetchDate()
感谢您的帮助
【问题讨论】:
【参考方案1】:你能把它加到willFinishLaunchingWithOptions
里面吗
func application(_ application: UIApplication, willFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool
FirebaseApp.configure()
return true
【讨论】:
或者我应该添加这个? 我试图用它代替我的 appdelagte 但我总是遇到同样的错误以上是关于快速打印数据库[重复]的主要内容,如果未能解决你的问题,请参考以下文章
解决 HttpServletRequest 流数据不可重复读