i using swxmlhash parse xml webpage
let xml = swxmlhash.parse(data) println(xml["root"]["schedule"]["date"].element?.text) this prints out element want. however, cannot seem store in string.
i declare string
var getxmlitem: string and try set equal xml element want:
getxmlitem = xml["root"]["schedule"]["date"].element?.text but gives me error:
value of optional type 'string?' not unwrapped; did mean use '!' or '?'?
is not way set equal xml? still learning swift confusing me.
swift takes hardline between values can null , values cannot null. thinktext optional within swxmlhash framrwork. try this:
getxmlitem = xml["root"]["schedule"]["date"].element?.text! you need sure text isn't nil though.
an alternative declare getxmlitem optional string:
var getxmlitem : string? what prefer swift infer type automatically:
var getxmlitem = xml["root"]["schedule"]["date"].element?.text // getxmlitem string?
Comments
Post a Comment