开发者

Error Building Project With NSXMLParserDelegate

TurbineXMLParser.h

#import <Foundation/Foundation.h>

@interface TurbineXMLParser : NSObject <NSXMLParserDelegate> {
...

TurbineXMLParser.m

#import "TurbineXMLParser.h"

I have just added a new class to my current project that I previously tested in a single file. When I try and build the project I get the error: error: cannot find protocol declaration for 'NSXMLParserDelegate'

I did a bit of searching and tried adding the following ...

TurbineXMLParser.h

#import <Foundation/Foundation.h>

@protocol NSXMLParserDelegate;

@interface TurbineXMLParser : NSObject <NSXMLParserDelegate> {
...

but still get the warning: warning: no definition of protocol 'NSXMLParserDelegate' is found

any help would be much appreciated

.
.
.

EDIT_002:

Removing <NSXMLParserDelegate> from the @interface did work, but I am curious as to why, am I getting mixed up & muddled? I was under the impression that the delegate object must adopt the NSXMLParserDelegate protocol i.e. adding <NSXMLParserDelegate> after the superclass.

I have two instances where this is working differently, the first 开发者_开发问答is a project in a single command line file where If I don't add <NSXMLParserDelegate> is warns that:

class 'TestXMLParser' does not implement the 'NSXMLParserDelegate' protocol

The second instance is where I have setup multiple *.h and *.m files (one of the classes being MyXMLParser.h, MyXMLParser.m) when I try to build the project with <NSXMLParserDelegate> I get this error:

error: cannot find protocol declaration for 'NSXMLParserDelegate'

Remove <NSXMLParserDelegate> and it all works fine, no errors, no warning...

gary


Forward-declaring NSXMLParserDelegate isn't likely to help, it needs to be actually imported if you're conforming to it.

The original error is what you'd get if you haven't linked the Foundation framework into your project.

Get-info your target in XCode. In the General tab, make sure Foundation.framework is in your list of linked libraries.


You don't need to define your object to be an NSXMLParserDelegate

Just make sure you do this:

NSXMLParser *parser = [[NSXMLParser alloc] initWithData:data];
[parser setDelegate:self];

And implement the methods in that object.

- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName 
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string


Although NSXMLParser was introduced from iOS2, The delegate hasn't been introduced until iOS4. Just remove the protocol declaration from your class, that worked for me when compiling against 3.2.

http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/NSXMLParserDelegate_Protocol/Reference/Reference.html


You do need to say it's an NSXMLParserDelegate in SDK4.0. But when I add to the interface definition, it no longer compiles under 3.0, just 4.0.

Under 3.0 it says that it cannot find the protocol def for NSXMLParserDelegate. I've included:

#import <Foundation/NSXMLParser.h>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜