Skip to content
This repository was archived by the owner on Nov 15, 2020. It is now read-only.

SwiftyJSON 4.0 compatibility#5

Open
aleciogomes wants to merge 1 commit into
malcommac:masterfrom
aleciogomes:swiftyjson-compat
Open

SwiftyJSON 4.0 compatibility#5
aleciogomes wants to merge 1 commit into
malcommac:masterfrom
aleciogomes:swiftyjson-compat

Conversation

@aleciogomes
Copy link
Copy Markdown

With the release of SwiftyJSON 4.0, the init method throws an exception if the data couldn't be parsed into a valid JSON. try can be banged since cache is valid or an empty Dataobject is passed as argument.

@Ruckt
Copy link
Copy Markdown

Ruckt commented Dec 1, 2017

I went with this:

    private lazy var cachedJSON: JSON = {
        do {
            return try JSON(data: self.data ?? Data())
        }
        catch { return JSON(Data()) }
    }()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants