We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Take the following for example:
<foo> <bar> <item></item> <bar> <bar> <item></item> <item></item> </bar> </foo>
You have to make a choice to either parse as a single item or an array [item]. Both options are not available.
item
[item]
The text was updated successfully, but these errors were encountered:
This is an interesting issue. I might have an idea on how to solve it.
Until the next release you can map the following example XML:
<foo> <bar> <item>1</item> </bar> <bar> <item>2</item> <item>3</item> </bar> </foo>
Using this trick:
class Foo: XMLMappable { var nodeName: String! var bar: [Bar]? required init(map: XMLMap) { } func mapping(map: XMLMap) { bar <- map["bar"] } } class Bar: XMLMappable { var nodeName: String! var items: [Int]? private var item: Int? required init(map: XMLMap) { } func mapping(map: XMLMap) { items <- map["item"] item <- map["item"] if let singleItem = item { items = [singleItem] } } }
It isn't pretty but will do the job.
Sorry, something went wrong.
Improving mapping of arrays for cases with single elements #3
1e5a562
Cheers! This worked.
gcharita
No branches or pull requests
Take the following for example:
You have to make a choice to either parse as a single
item
or an array[item]
. Both options are not available.The text was updated successfully, but these errors were encountered: