Git Product home page Git Product logo

Comments (5)

zwaldowski avatar zwaldowski commented on August 30, 2024

Good thinking; lots of questions raised. Exposing an option set would require that every parser implement every option, or that some mysteriously don't work. I don't like it.

from freddy.

jgallagher avatar jgallagher commented on August 30, 2024

Not necessarily. Right now we make NSJONSerialization conform to JSONParserType directly; we could wrap it up into something that took options, without exposing those options to other parsers. E.g.,

struct NSJSONSerializationWrapper: JSONParserType {
    private let options: NSJSONReadingOptions

    init(options: NSJSONReadingOptions = []) {
        self.options = options
    }

    static func createJSONFromData(data: NSData) throws -> JSON {
        return makeJSON(try NSJSONSerialization.JSONObjectWithData(data, options: options))
    }

    // makeJSON same as in our extension on NSJSONSerialization
}

Not very discoverable, but it'd do the trick.

from freddy.

hitsvilleusa avatar hitsvilleusa commented on August 30, 2024

Personally, I like @jgallagher's proposal because it at least exposes the options if they are needed. Without this, there is a chance that use of the NSJSONSerializationWrapper is a non-starter because I can't send it a certain configuration option, which I require. (It reminds me of registering cells for reuse in a table view but not being able to specify the cell style ... so you can't use the standard UITableViewCell styles with the register approach.)

from freddy.

jgallagher avatar jgallagher commented on August 30, 2024

This is a backwards compatible change, so it doesn't need to be decided prior to release. That said, a couple of bikeshedding options and what they'd look like to users:

  • Wrapper struct - what would the name of this be? I'll throw NSJSONSerializationWithOptions out for now but am not a big fan of that name.
let json = try JSON(data: data, usingParser: NSJSONSerializationWithOptions([.AllowFragments]))
  • Skip the wrapper struct and make NSJSONReadingOptions itself conform to JSONParserType:
let json = try JSON(data: data, usingParser: NSJSONReadingOptions([.AllowFragments]))

from freddy.

zwaldowski avatar zwaldowski commented on August 30, 2024

Closing due to inactivity and the general state of the repo.

from freddy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.