Replies: 4 comments
-
So, as I work through this, by the time |
Beta Was this translation helpful? Give feedback.
-
And the crux of my misunderstanding here is that the code I was using to determine if
This does not account for the case #2 above, and even worse, in case #3 I get an exception be Any suggestions are welcome. |
Beta Was this translation helpful? Give feedback.
-
For now, I came up with an
This solves the issue where I can call:
And things work in all 3 cases as desired. I can't finish the |
Beta Was this translation helpful? Give feedback.
-
So, I guess I have some questions and notes... In XML, quick note that there isn't a difference between So then, that means that the content of the The typical way this is handled with SWXMLHash is with optionals, like so: // required
let value: String = try parser["requiredElement"].value()
// optional
let value: String? = try parser["optionalElement"].value() Does that help? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I was looking at some of my code that was failing. I was trying to support both
<Boolean />
as well as potential values in<Boolean>xxx</Boolean>
and even complete lack of either as well.I can check to see if the
node["Boolean"].element != nil
, that will tell me whetherBoolean
was found at all in the node. But then I can't just sayboolean = try node["Boolean"].value()
on it since the shortcut version<Boolean />
will throw an exception with an empty value.How do I distinguish the three potential variants?
1 -
<Boolean />
2 -
<Boolean>xxx</Boolean>
3 - nothing at all
Ideally I'd like to say
let foo: Boolean? = node["Boolean"].value()
and I'd get nil for case 3, and a value for the other two cases.Beta Was this translation helpful? Give feedback.
All reactions