Comments (6)
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.
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.
What about raw enum
values?
from json-swift.
let array: JSON = [
JSValue(Foo.Bar.toRaw())
]
from json-swift.
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.
Good enough for me. Thanks!
from json-swift.
Related Issues (20)
- dyld_fatal_error: XCode 6.1 compiled code crashes on iPhone but not Simulator. HOT 6
- Double is not convertible to JSValue HOT 1
- Strange inconsistency when unwrapping a string HOT 1
- Unicode decoding issue HOT 2
- Array order different in app than in JSON API HOT 2
- Does not compile with 6.3 beta 4 HOT 2
- Does not compile in Xcode v6.3 (6D570) HOT 2
- Stringify should escape double quotes HOT 1
- How to install? HOT 1
- Support CocoaPods and Carthage HOT 1
- V2 doesn't support iOS? HOT 1
- Pretty printing output is invalid HOT 1
- Pretty printing arrays yields invalid json
- Swift 3.0 support HOT 1
- Some tests have been disabled for Linux.
- Enable Travis-CI builds for Linux. HOT 1
- Crash when parsing huge exponents HOT 3
- Crash when parsing many open array HOT 1
- Erroneously parsed strings HOT 2
- Performance
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from json-swift.