Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - implementing NSXMLParserDelegate

Tags:

swift

I'm trying to have a class of mine implement NSXmlProtocolDelegate but the compiler fails indicating that the class does not conform to NSObjectProtocol.

Is it required that all of the functions from NSObjectProtocol be implemented, or can that be avoided?

class GeoRssParser : NSXMLParserDelegate
{
    func parserDidStartDocument(parser : NSXMLParser)
    {

    }
}

Not much to see at this point - I got this far before the compiler started failing.

like image 753
Lee Avatar asked Jun 13 '14 10:06

Lee


1 Answers

Yes, at least anything that isn't tagged as @optional. The easiest way to achieve this would be to simply make your class a subclass of NSObject, which already conforms to the NSObjectProtocol, and implements all its methods.

class GeoRssParser: NSObject, NSXMLParserDelegate {
    func parserDidStartDocument(parser : NSXMLParser) {
        // stuff
    }
}
like image 172
Mick MacCallum Avatar answered Oct 29 '22 13:10

Mick MacCallum