我正在为 macOS 和 iOS 编写一个应用程序。
当我开始我的多平台项目时,我决定看看 Firebase SDK 是否适用于 macOS,因为我以前见过这个错误:
tvOS 和 macOS SDK 支持不是 Firebase 官方产品的一部分。相反,他们是社区支持的。详情见https://github.com/firebase/firebase-ios-sdk/blob/master/README.md。
我开始配置 Firebase,并且必须创建一个 NSApplicationDelegate 才能在 macOS 上运行:
class AppDelegate: NSObject, NSApplicationDelegate {
func applicationDidFinishLaunching(_ notification: Notification) {
FirebaseApp.configure()
}
}
Run Code Online (Sandbox Code Playgroud)
然后我使用 NSApplicationDelegateAdaptor 将此 AppDelegate 附加到我的 @main 应用程序:
@main
struct SchedulerApp: App {
@NSApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
Run Code Online (Sandbox Code Playgroud)
首先用一个简单的打印语句对其进行了测试 - 它奏效了。
然后用 测试它FirebaseApp.configure(),它抛出了一大堆错误。
沙盒不允许访问 com.apple.dnssd.service
dnssd_clientstub ConnectToServer: connect() failed path:/var/run/mDNSResponder Socket:4 Err:-1 …
在此代码中,我声明一个图表,其 x 比例域位于两个双精度数之间:
Chart(points, id: \.self) { point in
LineMark(
x: .value("time/s", point.timestamp),
y: .value("potential/mV", point.potential)
)
.foregroundStyle(by: .value("Electrode", point.electrode.symbol))
}
.chartXScale(domain: timeWindow)
// ...
Run Code Online (Sandbox Code Playgroud)
其中timeWindow声明如下:
var timeWindow: ClosedRange<Double> {
doc.contents.time(at: window.lowerBound)...doc.contents.time(at: window.upperBound)
}
Run Code Online (Sandbox Code Playgroud)
并time定义为:
func time(at index: Int) -> Double {
return Double(index) * (1 / sampleRate)
}
Run Code Online (Sandbox Code Playgroud)
然而,生成的图表 x 轴在我提供的下限和上限处没有起点和终点ClosedRange<Double>,而是在图的左侧和右侧有一段神秘空间:
如何使图表遵循我提供的域(边界也显示在底部工具栏工具栏项目组的文本视图中,使用代码Text("\(timeWindow.lowerBound.format()) s to \(timeWindow.upperBound.format()) s"))?如何让 y 轴呈现在图表左侧?
我正在使用 SwiftUI 构建一个应用程序,并有一个 ObservableObject 用于查询我的 Firestore 数据库。我的文档相对较大,并且经常需要查询很多文档,因此我想在查询下载数据时加入某种加载指示器。
这是我创建的 ObservableObject 的示例:
import FirebaseFirestore
import SwiftUI
struct Document: Identifiable, Equatable {
var id: String
var content: String
}
class Fetch: ObservableObject {
init(loading: Binding<Bool>) {
self._loading = loading
readDocuments()
}
@Published var documents: [Document] = []
@Binding var loading: Bool
var collection: CollectionReference = Firestore.firestore().collection("DOCUMENTS")
func newDocument(content: String) {
let id = self.collection.document().documentID
self.collection.document(id).setData(["id": id, "content": content]) { (error) in handleError(error: error, message: "\(id) CREATED") }
}
func deleteDocument(document: Document) {
if …Run Code Online (Sandbox Code Playgroud)