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
Cant Parse Dynamic object like array string and dictonary #317
Comments
your data property should be an array of objects like this:
Since there is support for single object to array this should work if you only get 1 pharmacy as an object instead of an array |
Sir my data variable is not fixed...sometime it's array..sometime it's string or sometime it's dictionary..when i work on codable decodable it's working fine..also I tried any and anyobject but not working |
If i work with codable then it's working fine.
|
Ah, then I think a property converter would be the way to go.
here the propertyConverters function will return a decodeConverter for the data element. This means that when the data element should be parsed it will use that function. It will have a parameter of type Any which comes from the raw json serialization. So indeed it could be a NSArray, NSDictionary or a simple type like String. So the code just checks the type by casting it and then creating the right enum for it. |
Didn't get you... please provide me model.. so i can move ahead .. I think you can't understand my question. One more time Explain you....
I give you example for understanding.. 1 ) if response is array class EmptyModelWithData : EVObject {
class EmptyModelWithData : EVObject { data variable type is not fixed.if you have proper solution then provide me..I waste my 5 days to solve this issue.Please provide me proper model of EVOBject. |
I updated my previous command so that it shows more of the model an dI added a comment |
Don't want codable ... I want using EVOBject...I have solved with codable |
Check this answer ... I have already Solved using Codable .. I want this using EVObject.. |
Please help me To go ahead I Stuck Here... My client is reviewing my code that's why I Finding a solution otherwise I go with codable.. Data is Generic Data type... i want like this class EmptyModelWithData : EVObject { |
What do you mean? This should work:
|
Yes I have solved my issue using following code:
|
But then if you use any, you don't have to cast. This would be good enough:
I wonder if you need a property converter at all when you use Any? Or maybe you would not need it when its of NSObject? |
I have stuck Here. don't know what is the solution I have to converted In any But when I pass this model to main view controller then I want to convert on model... Is it possible.. data(Any) if array then convert to let arrPharmacy : [PharmacyInfo]? data(Any) if dictionary then to let arrPharmacy : PharmacyInfo?
|
Please reply on this... |
EVObject has an init with dictionary an Array as an init with dictionaryArray. So if you make the base class of PharmacyInfo EVObject then you could do this: |
Finally i got my solution...THanks... |
Language : Swift
version : 5.0
Response from server
I have below model
**Code **
and i get the following warning: while doing this
WARNING: The class 'EmptyModelWithData' is not key value coding-compliant for the key 'data'
There is no support for optional type, array of optionals or enum properties.
As a workaround you can implement the function 'setValue forUndefinedKey' for this. See the unit tests for more information
Note: Data is not specific type. some time data is array. some time data is dictionary.
and sometime it would be string. so i create protocol but not working
I hope I get solution from here..
Thank you so much..
The text was updated successfully, but these errors were encountered: