iosjsonswiftquicktype

Quicktype option parameter handling


I have an optional parameter in my web-service response which can or can not return null. What will be the best what to manage those?

As if I pass null in creator lets say for this structure:

{
    "email": "test@test.com",
    "profilePicture": null,
    "firstTime": true,
    "preference1": {
        "$id": "26",
        "$values": []
    },
    "Preference2": {
        "$id": "27",
        "$values": []
    }
}

Now profilePicture is set to JSONNull and next time when I actually get profile URL it will not parse that and my response data to LNUser is nil. If I set this variable to String and null received response get set to nil.


Solution

  • You need

    let profilePicture:URL?