3

What does this error mean? This code compiled fine previous week. I noticed that when I change func parser to func something, there are no compilation errors, but the method, obviously, does not work at runtime and shows no output.

Any ideas?

enter image description here

**ERROR :** Objective-C method
'parser:didStartElement:namespaceURI:qualifiedName:attributes:'
provided by method
'parser(_:didStartElement:namespaceURI:qualifiedName:attributes:)'
conflicts with optional requirement method
'parser(_:didStartElement:namespaceURI:qualifiedName:attributes:)' in
protocol 'NSXMLParserDelegate'
2
  • Please provide the full error text Commented Apr 15, 2015 at 4:30
  • @matt I can get it. I repaired all the old stuff. But it this not supposed to work? I mean parse method is allowed in NSXMLParserDelegate right? As far as I can think, it must be something that I cannot understand the debug messages. Can you help figure out what that means? Commented Apr 15, 2015 at 4:40

3 Answers 3

6

If you look at the docs or the headers, you will see how to declare this method:

func parser(parser: NSXMLParser,
 didStartElement elementName: String,
    namespaceURI namespaceURI: String?,
   qualifiedName qualifiedName: String?,
      attributes attributeDict: [NSObject : AnyObject])

As you can see, those types are very different from the types you are using. You need to fix yours so they match these exactly.

Sign up to request clarification or add additional context in comments.

2 Comments

The thing is about attributes attributeDict: [NSObject : AnyObject]. I used a NSDictionary. Thanks. I would love a day of Swift free of Objective C. :)
Correct, you can't do that any more. Again, this is because the language and the APIs have changed since the (much?) earlier version of Xcode you must have been using when you originally wrote this code...
5

I had the same issue when I upgraded the swift version. I have used the above solution but it only fixed the compile time error not the runtime, i.e I was getting a nil after parsing the xml.

Solution which finally worked was

func parser(parser: NSXMLParser,didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String])

So what I have changed was type of argument of attributeDict: [NSObject: AnyObject] to attributeDict: [String: String] and it fixed the problem.

Comments

0

I was experiencing this issue, even after checking I was using the latest type in the signature as attributeDict: [String: String] however, realized that I was missing to also implement NSObject on my custom xml parser class, so adding NSObject to my custom class, like below, solved it:

class MyXmlParser: NSObject, NSXMLParserDelegate

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.