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

If I could supplement Teejay’s answer with some further information. This error:

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

is caused by a type mismatch.

For example having cast to your Swift array type:

    myPersonList = aDictionary["persons"] as [Person]

Accessing the value in aDictionary based upon key "persons", Swift expects to receive an array of type Person. This will compile and will execute without issue.

However, later in your code when accessing the myPersonList array element, if the type is not as specified – in my example Person – then execution will crash with the error above.

Bottom line: you almost certainly have specified the wrong type in the cast. Examine your dictionary object to see what it really contains.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)