Tags down


Thread 1: Fatal error: NSArray element failed to match the Swift Array Element type

By : user2175797
Date : October 14 2020, 02:24 PM
To fix this issue Okay, I've found the reason of this error. My messages array was being appended in another block of code with SBDUserMessages, and I wasn't cast them as exact type of message (as! SBDUserMessage).
The debugging really helped a lot. At some point I decided to call before the self.messages.append(newMessage) (where the crash actually occured), the messaged.removeAll(), and after that I've found out that everything works fine.
code :

Share : facebook icon twitter icon

executeFetchRequest throw fatal error: NSArray element failed to match the Swift Array Element type

By : Alexandre Bernardo
Date : March 29 2020, 07:55 AM
will help you I was able to reproduce your error message in the console. You get this message because you didn't set correctly your entity class name in the Core Data Model Editor (see image below).

fatal error nsarray element failed to match the swift array element type

By : Qingsong Shi
Date : March 29 2020, 07:55 AM
help you fix your problem An EndDiskMeridian cannot be stored in a dictionary, so you have to construct one yourself and pass the dictionary to it.
The following code works for me in a playground:
code :
import Foundation

class EndDiskMeridian:NSObject {
    var dispUcoefficients:Array<Double>
    var dispVcoefficients:Array<Double>
    var dispWcoefficients:Array<Double>

    init(dict: NSDictionary) {
        dispUcoefficients = dict["DispUcoefficients"] as Array<Double>
        dispVcoefficients = dict["DispVcoefficients"] as Array<Double>
        dispWcoefficients = dict["DispWcoefficients"] as Array<Double>

class EndDisk:NSObject {
    var numberOfDivisions:Int!
    var meridians:Array<EndDiskMeridian> = []

    init(dict:NSDictionary) {
        numberOfDivisions = dict["numberOfDivisions"] as Int
        let meridians = dict["meridians"] as NSArray
        for subdict in meridians {
            let endDiskMeridian = EndDiskMeridian(dict: subdict as NSDictionary)

let dict = ["EndDisk" : ["numberOfDivisions": 2, "meridians": [["DispUcoefficients": [1.0, 2.0], "DispVcoefficients": [3.0, 4.0], "DispWcoefficients": [5.0, 6.0]]]]]

let endDisk = EndDisk(dict: dict["EndDisk"]!)

Firebase iOS Swift fatal error: NSArray element failed to match the Swift Array Element type

By : Elaine Barnstable
Date : March 29 2020, 07:55 AM
it helps some times I am trying to fetch data from firebase database the format of data is below. , The issue is in your ChitObject class, specifially here:
code :
bidders = snapshotValue["bidders"] as! [Bidder]
init(snapshot: FIRDataSnapshot) {
    let snapshotValue = snapshot.value as! [String: AnyObject]
    chitId = snapshotValue["chitId"] as! Int
    chitName = snapshotValue["chitName"] as! String
    startDate = snapshotValue["startDate"] as! String
    endDate = snapshotValue["endDate"] as! String
    chitTotalAmt = snapshotValue["chitTotalAmt"] as! Int
    chitTotalMonths = snapshotValue["chitTotalMonths"] as! Int
    if let biddersArray = snapshotValue["bidders"] as? [[String:Any]] {
        bidders = biddersArray.flatMap{Bidder(dict:$0)}
    ref = snapshot.ref
class Bidder {

    var bidderId: Int
    var bidderName: String
    var bidderEmail: String
    var bidderPhone : String
    var modeOfPayment: Int
    var bidderBankName: String
    var bidderBankAcno: String
    var bidderIfscCode: String
    var paymentArray : [[String:String]]?
    var chitrefArray : [String]?
    var ref: FIRDatabaseReference?

    convenience init?(dict:[String:Any]) {
        guard let bidderId = dict["bidderId"] as? Int, let bidderName = dict["bidderName"] as? String, let bidderEmail = dict["bidderEmail"] as? String, let bidderPhone = dict["bidderPhone"] as? String, let modeOfPayment = dict["paymentType"] as? Int, let bidderBankName = dict["bankName"] as? String, let bidderBankAcno = dict["bankAccNumber"] as? String, let bidderIfscCode = dict["bankIFSC"] as? String else {
            return nil
        self.init(bidderId: bidderId, bidderName: bidderName, bidderEmail: bidderEmail, bidderPhone: bidderPhone, modeOfPayment: modeOfPayment, bidderBankName: bidderBankName, bidderBankAcno: bidderBankAcno, bidderIfscCode: bidderIfscCode, paymentArray: [[]], chitrefArray: [])

    init(bidderId: Int, bidderName: String,bidderEmail: String, bidderPhone: String, modeOfPayment: Int, bidderBankName: String, bidderBankAcno: String, bidderIfscCode: String,paymentArray:  [[String:String]], chitrefArray: [String]) {
        self.bidderId = bidderId
        self.bidderName = bidderName
        self.bidderEmail = bidderEmail
        self.bidderPhone = bidderPhone
        self.modeOfPayment = modeOfPayment
        self.bidderBankName = bidderBankName
        self.bidderBankAcno = bidderBankAcno
        self.bidderIfscCode = bidderIfscCode
        self.paymentArray = paymentArray
        self.chitrefArray = chitrefArray
        self.ref = nil

    init(snapshot: FIRDataSnapshot) {
        let snapshotValue = snapshot.value as! [String: AnyObject]
        bidderId = snapshotValue["bidderId"] as! Int
        bidderName = snapshotValue["bidderName"] as! String
        bidderEmail = snapshotValue["bidderEmail"] as! String
        bidderPhone = snapshotValue["bidderPhone"] as! String
        modeOfPayment = snapshotValue["modeOfPayment"] as! Int
        bidderBankName = snapshotValue["bidderBankName"] as! String
        bidderBankAcno = snapshotValue["bidderBankAcno"] as! String
        bidderIfscCode = snapshotValue["bidderIfscCode"] as! String
        paymentArray = snapshotValue["paymentArray"] as? [[String : String]]
        chitrefArray = snapshotValue["chitrefArray"] as? [String]
        ref = snapshot.ref

    func toAnyObject() -> Any {
        return [
            "bidderId" : bidderId,
            "bidderName" : bidderName,
            "bidderEmail": bidderEmail,
            "bidderPhone": bidderPhone,
            "modeOfPayment": modeOfPayment,
            "bidderBankAcno": bidderBankAcno,
            "paymentArray": paymentArray as Any,
            "chitrefArray" : chitrefArray as Any


Fatal error NSArray element failed to match the Swift Array Element type after xcode10.1 update

By : user2628212
Date : March 29 2020, 07:55 AM
hope this fix your issue The error message tells you that items was bridged from an NSArray (which does not enforce typing of its elements) but when Swift tried to retrieve an element, it did not find an instance of mainPageJobObj, which is what you said they array contained.
From the debug screen shot you can see that the items array actually contains instances of NSMutableDictionary.
code :
var items:[String:Any] = slider.mainPageObj.items!
let oneItem = items[index]
let name = oneItem["name"]

fatal error: NSArray element failed to match the Swift Array Element type

By : Mohammad
Date : March 29 2020, 07:55 AM
To fix the issue you can do If I could supplement Teejay's answer with some further information. This error:
Related Posts Related Posts :
  • Displaying button at the end of onboarding flow on swift
  • How to disable swipe back gesture globally in ionic 4 angular project
  • RxSwift: Reacting to different cell types
  • Register for notifications (FCM) outside AppDelegate
  • How do I save the background color using Swift?
  • iOS: didCompleteWithError, didReceive Response not triggered with URLSession.uploadTask
  • How can I create multiple relationships between the same entities in Coredata?
  • Issue with unwrapping [String] when using image cache
  • Swift and Xcode: How to Build and Run a GitHub repository of iOS Application?
  • Handing a completion with CloudKit
  • Update Uitableview cells button title
  • How to handle multiple text fields effectively in UITextField's shouldChangeCharactersIn
  • NativeScript RadListView component template
  • UITableViewCell constraints breaking when adding a new cell
  • How to implement a listener or while(true) to stop a waveform plot from scrolling once recorder has finished recording i
  • problem with attributed text for keyboard titleBarButton when using IQKeyBoardManager
  • iOS: Extract detected numbers and links from UITextView?
  • Does iOS/UIKit have built in support for scheduling scroll like dinging
  • Drawing directions from google map api
  • Bottom corners arent round
  • Keep original node lighting after using a light for another node
  • How to calculate proper keyboard contentInset for UIScrollView inside of a modally presented form sheet UIViewController
  • update key values of NSManagedObjects safely
  • Why would Xcode show MUCH more memory use than Instruments for SceneKit app?
  • iOS Drawer UI that only works when breakpoint inserted
  • 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' when inserting a row i
  • Problem when attempting to loop AVPlayer (userCapturedVideo) seamlessly
  • Accessing information within a NSDictionary
  • Importing and Using a Swift SnapshotTesting Framework with Carthage
  • How do I swap the first and second items in an array of strings?
  • How to soften begin and endUpdates in TableView
  • Proper way to create geometry base view in code
  • Passing data between two view controllers in a tab controller
  • PDF to Base64 on Ionic 3 app for Android and iOS platforms
  • PWA-Icon not used by iOS Devices
  • UICollectionView dynamic header size calculation
  • How best to remove all UIViewcontrollers and goto a single UIViewController?
  • How to generate Google Place API session token?
  • How to get all custom tableview cell textField and textView value outside tableView
  • How do I fix, App Store Rejected app for external tester: Reason: Performance: App Completeness?
  • Validate Alamofire Response for both HTTP 200 and 500 status codes
  • Sorting array of date from newest to oldest in Swift 4
  • How to check existing versions in Test Flight
  • Execute Completion Handler in DispatchGroup
  • shadow
    Privacy Policy - Terms - Contact Us © voile276.org