令人惊讶的是,在 Stack Overflow 搜索中输入此错误不会返回实际提到此错误 0.0 的结果
所以Event我的 Swift IOS 应用程序中有一个对象,它在 Firestore 上保存为文档,如下所示
和start字段end是时间戳。
在 xcode 上,当Event查询集合时,结果将Event使用此初始化程序解码为 s
init(document: DocumentSnapshot) {
self.id = document.documentID
let d = document.data()
self.title = d!["title"] as? String
let stamp = d!["start"] as? Timestamp
let estamp = d!["end"] as? Timestamp
self.start = stamp?.dateValue()
self.end = estamp?.dateValue()
/*
There is a breakpoint here!
*/
self.creator = d!["user"] as? String
self.isAllDay = (d!["isAllDay"] as? Bool)!
self.isPrivate = d!["isPrivate"] …Run Code Online (Sandbox Code Playgroud) 我正在使用 Swift 在 IOS 上构建一个日历,并使用 Firestore 后端。
我一次检索一个月中每一天的所有事件。
目前我只能显示在特定日期开始的事件。
如果活动在周五晚上开始并在周一早上结束(想想周末假期),那就不好了。
所以...
我需要Event从 Firestore 获取所有文档,其中当前填充事件的日期位于Firestore 文档上的start和字段的时间戳之间。end
显而易见的第一选择是这样的:
db.collection("Event")
.whereField("user", isEqualTo: userID)
.whereField("start", isLessThanOrEqualTo: thisDate)
.whereField("end", isGreaterThanOrEqualTo: thisDate)
.getDocuments()
Run Code Online (Sandbox Code Playgroud)
但事实证明 Firebase 不允许我在不同的字段上运行 2 个不等式过滤器 [:(
我能想到的唯一的其他选择是获取今天之前开始的所有事件,扫描每个事件并检查它是否在今天之前结束,然后显示其余的事件。
但这似乎效率不高,尤其是考虑到 5 年后,用户可能一年中的每一天都会发生一个事件(需要在短时间内检查大量文档)。
有人对我如何做到这一点有任何建议吗?
谢谢 :)
更新
我忘了添加这个,这是数据库结构的屏幕截图:)
(请注意day,由于我已经开始使用时间戳,因此month、 和year已过时)
我似乎在任何地方都找不到这方面的任何信息。所以我正在学习 SwiftUI,并且尝试将 a 添加Picker到 a Form,但选择器在点击时不会显示可用选项。我真的不知道还能告诉你们什么,所以有人可以看一下并帮助我解决这个问题吗?谢谢 :)
//Outside the body code
@State var contacts: [String] = [""]
@State var types: [Type] = [.mobile]
//Inside the body code and inside a Form{}
Section(header: Text("Contact")){
ForEach(0..<types.count, id: \.self) { i in
HStack{
Picker(selection: $types[i], label: Text(""), content: {
Text("Mobile").tag(Type.mobile)
Text("Land Line").tag(Type.landline)
Text("Email").tag(Type.email)
}).pickerStyle(DefaultPickerStyle())
.frame(width: 80.0)
TextField("Insert Detail", text: $contacts[i])
}
}
Button("Add Another") {
types.append(.mobile)
contacts.append("")
}
Run Code Online (Sandbox Code Playgroud)