I'm having problem checking if the xml element has desire tag or not :
I wrote my code like below :
//checking if link is empty
if xml["rss"]["channel"]["item"][index]["source"].element!.attributes["url"] != "" {
Link = (xml["rss"]["channel"]["item"][index]["source"].element?.attributes["url"])!
} else {
Link = ""
}
When I run this code i get error of : Thread3 EXC_BAD_INSTRUCTION , for the first line of my code ,but when I run the code like below : it goes through if and does not understand that source element is not exist at all! code :
//checking if link is empty
if (xml["rss"]["channel"]["item"][index]["source"].element?.attributes["url"] as String?) != nil {
Link = (xml["rss"]["channel"]["item"][index]["source"].element?.attributes["url"] as String?)!
} else {
Link = ""
}
How check if source element is exist or not in swift 2 ?
Aucun commentaire:
Enregistrer un commentaire