![](/img/trans.png)
[英]My app crashes when running on my iPhone, but not in the simulator. What are some debugging techniques I can use to reso the issue?
[英]I get nil on a variable when running app on iPad3 but not on simulator. Swift 4
在我的第一個應用程序中,我有一個函數以[String:String]
字典形式發布到Firebase,在Firebase中,我看到發布的所有值都是String
。 在我的第二個應用程序中,我有一個讀取該節點並也以[String:String]
檢索的函數,但是在快照中打印了兩個值, Booking Date
和Booking Id
看起來像Int
。 我不是真正讓他們Int
就像我需要他們,當我在模擬器上運行我的第二個應用程序iOS 12.1
it't都好,按預期工作,但是當我在我的iPad 3運行iOS 9.3.5
的應用程序崩潰,因為let bookingId = Int(value["Booking Id"]!)
為nil,但是如果let bookingDate = Int(value["Booking Date"]!)
則不會發生這種情況。 似乎iPad不喜歡轉換多個值。 您看到對此有任何解決方案嗎? 這是函數:
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
一樣:
Snap (Workshop Bookings) {
"-Lb4XzGtLtnBAgoPB6Ay" = {
"Booking Date" = 20190329;
"Booking End" = "14:00";
"Booking Id" = 201903291300;
"Booking Start" = "13:00";
"Shop Logo Url" = "https://firebasestorage.googleapis.com/v0/b/fix-it-b4b00.appspot.com/o/Spezial%20Cycle%2FSpezial%20Cycle%20logo.png?alt=media&token=016cc976-ae8d-4c71-a77f-a899d661be20";
"Shop Name" = "Spezial Cycle";
"User Name" = "";
"Works List" = "Revisione Generale, ";
};
}
我認為問題在於您的iPad 3仍在32位數據總線上運行,並且值201903291300太大而無法放入該Int32
(這是32位體系結構上的Int
實現)。
您應該嘗試使用Int64
而不是Int
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.