"Precondition failed: NSArray element failed to match the Swift Array Element type" error on iOS version < 13 but works fine on iOS 13 and 14.

I've got a class derived from UIView called ContentListView that goes like this:

It is used in the view controller like this:

But when I tried to run it on iOS 11 and 12 (both simulators and actual devices), it crashed. Although it worked on iOS 13 and 14. It crashed with this error:

Precondition failed: NSArray element failed to match the Swift Array Element type
Expected ContentListView but found UIView: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1001.0.82.4/swift/stdlib/public/core/ArrayBuffer.swift, line 346
2021-09-22 13:24:27.624568+0700 Kolibree[16970:513272] Precondition failed: NSArray element failed to match the Swift Array Element type
Expected ContentListView but found UIView: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1001.0.82.4/swift/stdlib/public/core/ArrayBuffer.swift, line 346

The contentListViews in the storyboard themselves are of the type ContentListView so the error seems weird. How do I solve this? It has been days and I'm stuck at this. :(

Thanks in advance.

Answers

It looks like the contentListViews items (or some of them in the array) are not defined (in IB) as ContentListView but just UIView.

Check all the elements of the IBOutlet collection in the storyboard.

  • If that's the case, won't it also break on iOS 13 and 14? Because it didn't and only crashed on iOS 11 and 12.

  • @bawenang.zyrous, why do you think so? There are many cases where sort of bad coding get apparent only in some specific conditions.

  • Confirm OOPer: some errors do not show until they hit a wall on a new version of OS… Did you check what I proposed you to check, before arguing whether or not iOS should do this and that ?

Add a Comment