swift - NSXMLParser: How to return the parseError if .parse() returns false? -


in swift, have been experimenting nsxmlparser. in general confident concepts , implementation.

therefore have, example, function myfunc() include call .parse() method.

in event .parse() method returns false how can use delegate function parser(parser: nsxmlparser, parseerroroccurred parseerror: nserror) return parseerror directly myfunc()? how can access error?

i know print error. , can see assign value variable class level scope. guessing there better of getting it.

func myfunc() {     // ...     myxmlparser!.delegate = self     if myxmlparser!.parse() != true {        // ...     } } 

and implement delegate functions

func parser(parser: nsxmlparser, didstartelement elementname: string, namespaceuri: string?, qualifiedname qname: string?, attributes attributedict: [string : string]) {      // ... }  func parser(parser: nsxmlparser, foundcharacters string: string) {     // ... }  func parser(parser: nsxmlparser, didendelement elementname: string, namespaceuri: string?, qualifiedname qname: string?) {     // ... }  func parser(parser: nsxmlparser, parseerroroccurred parseerror: nserror) {     // know print(parseerror) or assign value variable wth class level scope } 

how can return parseerror or otherwise access myfunc() without passing value variable wider scope?

if parse() method of nsxmlparser returns false can use

var parsererror: nserror? { } // can called after parse on determine parser state. 

property information problem. the

var linenumber: int { } var columnnumber: int { } 

properties give more information location of error. example:

if !myxmlparser.parse() {     let error = myxmlparser.parsererror     let line = myxmlparser.linenumber     let col = myxmlparser.columnnumber     println("xml parsing failed @ \(line):\(col): \(error?.localizeddescription)") } 

Comments

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -