Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash in NSArray #322

Open
khushbuInexture opened this issue Jan 4, 2021 · 7 comments
Open

Crash in NSArray #322

khushbuInexture opened this issue Jan 4, 2021 · 7 comments

Comments

@khushbuInexture
Copy link

khushbuInexture commented Jan 4, 2021

Hello,

I'm getting this crash sometimes. I am not able to reproduce this everytime.

if theValue is Array {
return (theValue as AnyObject, valueType, false)
}

Precondition failed: NSArray element failed to match the Swift Array Element type
Expected CountryRatesDetailModel but found __NSDictionaryI: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1100.2.280/swift/stdlib/public/core/ArrayBuffer.swift, line 354
2021-01-04 11:33:13.527870+0530[8041:61326] Precondition failed: NSArray element failed to match the Swift Array Element type
Expected CountryRatesDetailModel but found __NSDictionaryI: file /BuildRoot/Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-1100.2.280/swift/stdlib/public/core/ArrayBuffer.swift, line 354
2021-01-04 11:35:39.520740+0530[8041:62506] XPC connection interrupted
Screenshot 2021-01-04 at 11 45 35 am
Screenshot 2021-01-04 at 11 44 43 am

@evermeer
Copy link
Owner

evermeer commented Jan 4, 2021

As you can see in the debug log it found an NSDictionary where it expected an Array.
If you have an array of objects, then EVReflection should handle a single object, that was not an array in the json, as an array.
How did you specify the array in the target object?

@khushbuInexture
Copy link
Author

khushbuInexture commented Jan 5, 2021

we have one object which have array of object...as you can see in screen shot I'm simply using EVReflection pod to convert json to our class object...CountryRateDataModel has array of object.

class CountryRateModel: EVObject {
var status = ""
var success = Bool()
var message = ""
var data = CountryRateDataModel()
var meta = ""
}
class CountryRateDataModel: EVObject {
var rates = CountryRatesDetailModel
}

I don't know why it found NSDictornary...perhaps when array is empty then it is not being handled properly by EVReflection class.Also this crash is not happening everytime..but it is reported sometimes in my live application and affecting the performance.

@evermeer
Copy link
Owner

evermeer commented Jan 5, 2021

I don't seen an array definition in you class. Most fields are strings. 2 are sub objects. The bool should be defined an other way. see the readme about booleans. There are various ways to define an array, please show me your class definition that includes the array.

@khushbuInexture
Copy link
Author

khushbuInexture commented Jan 5, 2021

Array of object here is being converted to URL..please refer the screen shot i have attached..here we have CountryRatesDetailModel as array of object which is being stored in rates variable.

Screenshot 2021-01-05 at 5 25 59 pm

@evermeer
Copy link
Owner

evermeer commented Jan 5, 2021

That looks OK. If you also have a Json that is causing the error, then I could create a unit test to see what's going on and reproduce the issue and maybe fix it.

Besides that, are you sure the Bool() value works?

@khushbuInexture
Copy link
Author

khushbuInexture commented Jan 6, 2021

Yes Bool() does work...please find json response.

{
"status" : "200",
"success" : true,
"message" : "Fetched all countries rate calculation.",
"data" : {
"rates" : [
{
"country" : "Liechtenstein"
},
{
"country" : "Spain"
},
{
"country" : "Cyprus"
},
{
"country" : "Ghana"
},
{
"country" : "Benin"
},
{
"country" : "Netherlands The"
},
{
"country" : "Ireland"
},
{
"country" : "Lithuania"
},
{
"country" : "Latvia"
},
{
"country" : "Malta"
},
{
"country" : "Kosovo"
},
{
"country" : "Croatia (Hrvatska)"
},
{
"country" : "Bulgaria"
},
{
"country" : "Greece"
},
{
"country" : "Slovenia"
},
{
"country" : "Norway"
},
{
"country" : "Luxembourg"
},
{
"country" : "Germany"
},
{
"country" : "Belgium"
},
{
"country" : "Estonia"
},
{
"country" : "Ukraine"
},
{
"country" : "Senegal"
},
{
"country" : "Italy"
},
{
"country" : "Austria"
},
{
"country" : "Romania"
},
{
"country" : "Finland"
},
{
"country" : "Slovakia"
},
{
"country" : "Iceland"
},
{
"country" : "Sweden"
},
{
"country" : "Nigeria"
},
{
"country" : "France"
},
{
"country" : "Denmark"
},
{
"country" : "Portugal"
},
{
"country" : "Hungary"
}
]
},
"meta" : ""
}

@khushbuInexture
Copy link
Author

Hello,

Is there any update? Are you able to reproduce the crash based on this JSON?

Let me know if you have made any updates so I can update the pods?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants