Skip to content
This repository has been archived by the owner on May 20, 2021. It is now read-only.

Added ability to fallback nil values #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Added ability to fallback nil values #55

wants to merge 1 commit into from

Conversation

hebertialmeida
Copy link

This is the reborn of #36, as it was closed and I think it is relevant. Some APIs require sending null values for properties, this approach is interesting because keep the JSON clean and you can only override the ones you need.

Like:

struct Image: WrapCustomizable {
    let name
    let path: String?

    fileprivate func fallbackValueForProperty(propertyNamed propertyName: String) -> Any? {
        if propertyName == "path" {
            return NSNull()
        }
        return nil
    }
}

will wrap to a JSON like this:

{
    "name": "image.jpg",
    "path": null
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
1 participant