8

I'm currently working on learning Swift 3 and I'm trying to implement an XML parser that parses data from a URL. I've created a separate file to handle the XML parsing and have setup it as follows.

 let xmlDoc  = NSURL(string: "http://labs.bible.org/api/?passage=random&type=xml")

 var parser1 = XMLParser(contentsOf: xmlDoc)    

I'm currently having issues with syntax however. Swift is highlighting the line where I initialize the XML Parser and giving the error "Cannot use instance member 'xmlDoc' within property initializer, property initializers run before 'self' is available.

This is probably something really simple but I wasn't able to find a solution in my google searches.

Any feedback is appreciated!

-Alex

  • Nice that they've updated the error message – used to be a vague "Instance member X cannot be used on type Y" – Hamish Aug 22 '16 at 21:34
  • You can't call 'xmlDoc' within property initializers. You can initialize 'parser1' within another method such as viewDidLoad etc – swathy krishnan Jun 21 '17 at 09:37

0 Answers0