GithubHelp home page GithubHelp logo

Comments (6)

paulyoung avatar paulyoung commented on July 18, 2024

Similarly (but not involving enum), this:

let foo = [
    "bar"
]

let dictionary: JSON = [
    "foo": foo
]

Results in:
Dictionary<$T3, $T4>' is not convertible to 'JSON'

from json-swift.

owensd avatar owensd commented on July 18, 2024

Perfectly reasonable... but Swift doesn't allow implicit type conversion. Since those are not literals, they cannot be converted.

A couple of options:

let foo: JSValue = [
    "bar"
]

let dictionary: JSON = [
    "foo": foo
]

Or:

var array = [JSValue]()
array.append("Item #1")

var json = JSValue(array)

from json-swift.

paulyoung avatar paulyoung commented on July 18, 2024

What about raw enum values?

from json-swift.

owensd avatar owensd commented on July 18, 2024
let array: JSON = [
    JSValue(Foo.Bar.toRaw())
]

from json-swift.

owensd avatar owensd commented on July 18, 2024

Pre-beta 6 there was a __conversion() override we could implement; this allowed converting Strings, Ints, etc... implicitly. That is now removed so when you deal with instances of types, you need to box them into a JSValue.

It sucks.

from json-swift.

paulyoung avatar paulyoung commented on July 18, 2024

Good enough for me. Thanks!

from json-swift.

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.