在第一个应用程序中,我有一个函数以[String:String]
字典的形式发布到Firebase,在Firebase中,我看到发布的所有值都是String
。在我的第二个应用程序中,我有一个读取该节点并也以[String:String]
检索的函数,但是在快照打印中,Booking Date
和Booking Id
这两个值看起来像Int
。然后,我实际上像使它们Int
一样,就像我需要它们那样,当我在模拟器iOS 12.1
上运行第二个应用程序时,它并没有达到预期的效果,而是在iPad 3上运行了{ {1}}因iOS 9.3.5
为零而崩溃,但这let bookingId = Int(value["Booking Id"]!)
并没有发生。好像iPad没
就像转换多个值一样。
您看到对此有任何解决方案吗?
这是函数:
let bookingDate = Int(value["Booking Date"]!)
这是快照打印,显示func getMyBookings() {
let ref = Database.database().reference()
ref.child("Continent").child("Europe").child("Country").child("Italy").child("Region").child("Emilia-Romagna").child("City").child("Bologna").child("Shops").child("Workshop Bookings").queryOrdered(byChild: "Shop Name").queryEqual(toValue: "Spezial Cycle").observe(.value) { (snapshot) in
// ref.child("Continent").child("Europe").child("Country").child("Italy").child("Region").child("Emilia-Romagna").child("City").child("Bologna").child("Shops").child("Workshop Bookings").queryOrdered(byChild: "Shop Name").queryEqual(toValue: "Spezial Cycle").observe(.childAdded, with: { (snapshot) in
print(snapshot)
if let data = snapshot.value as? [String: [String:String]] {
for (_, value) in
data{
let bookingDate = Int(value["Booking Date"]!)!
// let bookingDate = value["Booking Date"]!
print("bookingDate is: \(String(describing: bookingDate))")
let bookingStart = value["Booking Start"]
let bookingEnd = value["Booking End"]
let customerName = value["User Name"]
let bookingId = Int(value["Booking Id"]!)!
print("bookingId is :\(String(describing: bookingId))")
let booking: (bookingDate: Int, bookingStart: String, bookingEnd: String, customerName: String, bookingId: Int) = (bookingDate!, bookingStart!, bookingEnd!, customerName!, bookingId: bookingId)
print("booking is: \(booking)")
self.bookingsArray.append(booking)
self.calculateBookedTimeSlots()
}
self.calculateBookedTimeSlots()
if #available(iOS 10.0, *) {
let actions: [UNNotificationAction] = [UNNotificationAction(identifier: "chiudi", title: "Chiudi", options: [.foreground])]
Notifications.newTimeIntervalNotification(notificationType: "New booking", actions: actions, categoyIdentifier: "New Booking", title: "Nuova prenotazione", body: "Hai una nuova prenotazione", userInfo: [:], timeInterval: 5, repeats: false)
} else if #available(iOS 9.0, *){
// Fallback on earlier versions
Notifications.newTimeIntervalNotification(notificationType: "New booking", actions: [], categoyIdentifier: "New Booking", title: "Nuova prenotazione", body: "Hai una nuova prenotazione", userInfo: [:], timeInterval: 5, repeats: false)
}
}
// })
}
}
和Booking Date
看起来像Booking Id
:
Int
答案 0 :(得分:1)
我认为问题在于您的iPad 3仍在32位数据总线上运行,并且值201903291300太大了,无法放入该Int32
(这是Int
的实现) 32位架构)。
您应该尝试使用Int64
而不是Int