简体   繁体   English

在iPad3上运行应用程序时,在模拟器上没有变量,但变量没有显示。 斯威夫特4

[英]I get nil on a variable when running app on iPad3 but not on simulator. Swift 4

In my 1st app I have a function that posts to Firebase as [String:String] dictionary, and in Firebase I see all values posted are String . 在我的第一个应用程序中,我有一个函数以[String:String]字典形式发布到Firebase,在Firebase中,我看到发布的所有值都是String In my 2nd app I have a function that reads that node and retrieves as [String:String] also, but in the snapshot print two of the values, Booking Date and Booking Id look like Int . 在我的第二个应用程序中,我有一个读取该节点并也以[String:String]检索的函数,但是在快照中打印了两个值, Booking DateBooking Id看起来像Int I than actually make them Int like I need them to be and when I run my 2nd app on simulator iOS 12.1 it't all good and works as expected, but when I run it on my iPad 3 iOS 9.3.5 app crashes because let bookingId = Int(value["Booking Id"]!) is nil, but that doesn't happen with let bookingDate = Int(value["Booking Date"]!) . 我不是真正让他们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"]!)则不会发生这种情况。 Looks like iPad doesn't like converting more than one value. 似乎iPad不喜欢转换多个值。 Do you see any solution to this? 您看到对此有任何解决方案吗? Here is the function: 这是函数:

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)
            }
        }
        //        })
    }
}

And this is the snapshot print showing both Booking Date and Booking Id looking like Int : 这是快照打印,显示Booking DateBooking IdInt一样:

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, ";
    };
} 

I think the problem is that your iPad 3 is still running on a 32 bit data bus, and the value 201903291300 is slightly too large to fit into that Int32 (which is the Int implementation on 32 bit architecture). 我认为问题在于您的iPad 3仍在32位数据总线上运行,并且值201903291300太大而无法放入该Int32 (这是32位体系结构上的Int实现)。

You should try to use Int64 instead of Int 您应该尝试使用Int64而不是Int

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的应用程序在我的iPhone上运行时崩溃,但不在模拟器中崩溃。 我可以使用哪些调试技术来解决问题? - 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? 如何检查 iOS 应用程序是否在模拟器上运行。 (目标-c) - How to check if an iOS app is running on the simulator. (objective-c) iPad3上缺少图层阴影(但可在模拟器中使用) - Layer Shadow Missing on iPad3 (but works in Simulator) 我的iPhone应用程序不会在新的iPhone 5模拟器中使用信箱运行。 我怎么把它拿到信箱? - My iPhone App won't run with letterboxes in the new iPhone 5 simulator. How do I get it to letterbox? iPad2应用程序可以在iPad3上运行吗? - Will iPad2 app work on iPad3? Swift / Backendless-Facebook Login在iPhone上有效,但在iPad Simulator上无效。 如何正确使用Facebook SDK? - Swift / Backendless - Facebook Login working on iPhone, but not on iPad Simulator. How to properly use Facebook SDK? 检测应用程序是否在iPad模拟器中运行 - Detect if app is running in iPad simulator 在 Swift 上运行应用程序时意外发现“nil” - Unexpectedly found 'nil' when running app on Swift 应用启动在模拟器上的速度明显慢。 - App Launch noticeably slow on simulator. 在Swift中使用NSDateFormatter时我得到零 - I get nil when using NSDateFormatter in swift
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM