firebase-ios-sdk: Firestore crashing with `FIRQueryDocumentSnapshot` and Swift's map function in SwiftUI canvas
Step 0: Are you in the right place?
Yes
[REQUIRED] Step 1: Describe your environment
- Xcode version: 11.3.1 (11C504)
- Firebase SDK version: 6.16.0
- Firebase Component: Firestore
- Component version: 1.10.0
- Installation method:
CocoaPods
[REQUIRED] Step 2: Describe the problem
Steps to reproduce:
If I would like to call map on a documents array from firestore, the SwiftUI canvas in Xcode crashes.
Note that the same code works flawlessly if I run the app in the simulator. Only the canvas view is affected. With canvas I refer to the PreviewProvider feature in SwiftUI.
Please also note that https://github.com/firebase/firebase-ios-sdk/issues/4271 is somehow related - but in my case I don’t have multiple internal frameworks.
Crashlog:
Precondition failed: NSArray element failed to match the Swift Array Element type
Expected FIRQueryDocumentSnapshot but found FIRQueryDocumentSnapshot: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1100.2.280/swift/stdlib/public/core/ArrayBuffer.swift, line 354
Relevant Code:
self.db.collectionGroup("Foo").addSnapshotListener { querySnapshot, err in
guard let documents = querySnapshot?.documents else {
return
}
let data = documents.map { Foo(document: $0) } // canvas crash
[...]
}
About this issue
- Original URL
- State: open
- Created 4 years ago
- Comments: 18 (9 by maintainers)
I had the same problem with cocoapods umbrella frameworks and I solve problem with loop “for i in 0…<document.count” just read the code bellow
Maybe it’s not the better way but it works
Done. Thanks for the hint. I googled before to make sure it is okay to push (https://stackoverflow.com/a/44937513/4041516). I was uncomfortable though, and made the demo db at least readonly 😃 But now, even better - no
GoogleService-Info.plistanymore! Of course you now have to setup your own db.Thank you very much for doing that - can you please delete the project and re-upload it without a
GoogleService-Info.plist? Just want to make sure it’s not easily accessible.Should be reproducible, but I’m going to create a minimum project that I can share.