Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No mechanism to create empty object. #197

Closed
richburdon opened this issue Apr 9, 2015 · 3 comments
Closed

No mechanism to create empty object. #197

richburdon opened this issue Apr 9, 2015 · 3 comments

Comments

@richburdon
Copy link

There doesn't seem to be a mechanism to create an empty dictionary object? Since [] in swift can be interpreted as an empty array or empty object. And,

var json:JSON = JSON([])

creates an empty array, so you can't add properties.

E.g., This would seem to be appropriate, but doesn't work

var json:JSON = JSON()
json["id"].intValue = 123
println(json)
{
"id": 123
}

@chschu
Copy link
Contributor

chschu commented Apr 16, 2015

In Swift, [:] represents an empty dictionary, but SwiftyJSON doesn't have an dictionary-based initializer yet. This should be quite easy to add.

@chschu
Copy link
Contributor

chschu commented Apr 16, 2015

Just checked it: var json:JSON = [:] works, because JSON implements the DictionaryLiteralConvertible protocol.

@dbsima
Copy link

dbsima commented May 14, 2015

I think this issue can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants