ios – Decoder always set optional property to nil


I’m trying to decode a custom type from a json. As seen in the image, it is about the “userInfo” property. For some reason it is alway setting it to nil. If I change the declaration of the property to

let userInfo: UserInfo

then the decode is working properly. But I need this value to be optional and I can’t find a way to make it work even thou’ the decode is working properly.

In the second image you can se the user object that’s been decoded and the “userInfo” property being nil.

Here is the JSON response

"user": {
    "user_id": "adec4c71-524a-48cb-add1-e36908bf32b6",
    "username": "Andrei Simedre",
    "email": "[email protected]",
    "password": "$2b$10$3rBP8A3N6TQ5RSioiCv3VenDCcOGJFp6FuPVDgyf0n6.R5uN0eYyO",
    "user_info": {
        "id": "2cc741cd-5de6-4fe8-a3d4-e96a3d11f33c",
        "user_id": "adec4c71-524a-48cb-add1-e36908bf32b6",
        "dob": "22-01-1994",
        "favorite_sport": "Basketball",
        "phone_number": "0761646973",
        "gender": "Masculine"
    }
}

I also use decoding strategy to convert from snake case to camel case.

enter image description here

enter image description here

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img