Obj-C解析错误

时间:2011-04-29 13:12:26

标签: objective-c parsing compilation

我在命名空间变量向前和init方法的@synthesize指令旁边找到了“!预期标识符或'('”旁边的#import,以及“缺少属性实现的上下文”。

SoapService.h

#import "SoapDelegate.h"
@interface SoapService : NSObject
{
    NSString* _serviceUrl;
    NSString* _namespace;
    NSString* _username;
    NSString* _password;
    NSDictionary* _headers;
    BOOL _logging;
    id<SoapDelegate> _defaultHandler;
} 

@property (retain) NSString* serviceUrl;
@property (retain) NSString* namespace;
@property (retain) NSString* username;
@property (retain) NSString* password;
@property (retain) NSDictionary* headers;
@property BOOL logging;
@property (nonatomic, retain) id<SoapDelegate> defaultHandler;

- (id) initWithUrl: (NSString*) url; - (id) initWithUsername: (NSString*) serviceUsername andPassword: (NSString*) servicePassword;

@end

SoapService.m

#import "SoapService.h"

@implementation SoapService

@synthesize serviceUrl = _serviceUrl;
@synthesize namespace = _namespace;
@synthesize logging = _logging;
@synthesize headers = _headers;
@synthesize defaultHandler = _defaultHandler;
@synthesize username = _username;
@synthesize password = _password;

- (id) init {

    if ((self = [super init])) {
        self.serviceUrl = nil;
        self.namespace = nil;
        self.logging = NO;
        self.headers = nil;
        self.defaultHandler = nil;
        self.username = nil;
        self.password = nil;
    }
    return self;
}

- (id) initWithUrl: (NSString*) url {

    if((self = [self init])) {
        self.serviceUrl = url;
    }
    return self;
}

- (id) initWithUsername: (NSString*) serviceUsername andPassword: (NSString*) servicePassword {

    if ((self = [self init])) {
        self.username = serviceUsername;
        self.password = servicePassword;
    }
    return self;
}

-(void)dealloc {

    [_serviceUrl release];
    [_namespace release];
    [_username release];
    [_password release];
    [_headers release];
    [_defaultHandler release];
    [super dealloc];
}

@end

SoapDelegate.h

#import "SoapFault.h"

@protocol SoapDelegate <NSObject>
- (void) onload: (id) value;
@optional
- (void) onerror: (NSError*) error;
- (void) onfault: (SoapFault*) fault;
@end
  

我看不出有什么不对!我试过了   从中更改变量名称   命名空间到namespacexx,但没有   成功。

SoapFault.h

#import "TouchXML.h"

@interface SoapFault : NSObject {
    NSString* faultCode;
    NSString* faultString;
    NSString* faultActor;
    NSString* detail;
    BOOL hasFault;
}

@property (retain, nonatomic) NSString* faultCode;
@property (retain, nonatomic) NSString* faultString;
@property (retain, nonatomic) NSString* faultActor;
@property (retain, nonatomic) NSString* detail;
@property BOOL hasFault;

+ (SoapFault*) faultWithData: (NSMutableData*) data;
+ (SoapFault*) faultWithXMLDocument: (CXMLDocument*) document;
+ (SoapFault*) faultWithXMLElement: (CXMLNode*) element;

@end

TouchXML.h

#import "CXMLDocument.h"
#import "CXMLElement.h"
#import "CXMLNode.h"
#import "CXMLNode_XPathExtensions.h"
  

我可以走得更远,但愿意   声明我正在使用Xcode进行编译   4.0.2和之前版本的Xcode编译器没有提出这些   语义问题。这导致我   相信有一些语法或   已弃用的符号。

CXMLDocument.h

#import "CXMLNode.h"

enum {
    CXMLDocumentTidyHTML = 1 << 9
};

@class CXMLElement;

@interface CXMLDocument : CXMLNode {
    NSMutableSet *nodePool;
}

- (id)initWithXMLString:(NSString *)inString options:(NSUInteger)inOptions error:(NSError **)outError;
- (id)initWithContentsOfURL:(NSURL *)inURL options:(NSUInteger)inOptions error:(NSError **)outError;
- (id)initWithData:(NSData *)inData options:(NSUInteger)inOptions error:(NSError **)outError;

//- (NSString *)characterEncoding;
//- (NSString *)version;
//- (BOOL)isStandalone;
//- (CXMLDocumentContentKind)documentContentKind;
//- (NSString *)MIMEType;
//- (CXMLDTD *)DTD;

- (CXMLElement *)rootElement;

//- (NSData *)XMLData;
//- (NSData *)XMLDataWithOptions:(NSUInteger)options;

//- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error;
//- (id)objectByApplyingXSLTString:(NSString *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error;
//- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL arguments:(NSDictionary *)argument error:(NSError **)error;

//- (id)XMLStringWithOptions:(NSUInteger)options;

@end

CXMLNode.h

#import <Foundation/Foundation.h>

#include <libxml/tree.h>

typedef enum {
    CXMLInvalidKind = 0,
    CXMLElementKind = XML_ELEMENT_NODE,
    CXMLAttributeKind = XML_ATTRIBUTE_NODE,
    CXMLTextKind = XML_TEXT_NODE,
    CXMLProcessingInstructionKind = XML_PI_NODE,
    CXMLCommentKind = XML_COMMENT_NODE,
    CXMLNotationDeclarationKind = XML_NOTATION_NODE,
    CXMLDTDKind = XML_DTD_NODE,
    CXMLElementDeclarationKind =  XML_ELEMENT_DECL,
    CXMLAttributeDeclarationKind =  XML_ATTRIBUTE_DECL,
    CXMLEntityDeclarationKind = XML_ENTITY_DECL,
    CXMLNamespaceKind = XML_NAMESPACE_DECL,
} CXMLNodeKind;

@class CXMLDocument;

// NSXMLNode
@interface CXMLNode : NSObject {
    xmlNodePtr _node;
}

- (CXMLNodeKind)kind;
- (NSString *)name;
- (NSString *)stringValue;
- (NSUInteger)index;
- (NSUInteger)level;
- (CXMLDocument *)rootDocument;
- (CXMLNode *)parent;
- (NSUInteger)childCount;
- (NSArray *)children;
- (CXMLNode *)childAtIndex:(NSUInteger)index;
- (CXMLNode *)previousSibling;
- (CXMLNode *)nextSibling;
//- (CXMLNode *)previousNode;
//- (CXMLNode *)nextNode;
//- (NSString *)XPath;
//- (NSString *)localName;
//- (NSString *)prefix;
//- (NSString *)URI;
//+ (NSString *)localNameForName:(NSString *)name;
//+ (NSString *)prefixForName:(NSString *)name;
//+ (CXMLNode *)predefinedNamespaceForPrefix:(NSString *)name;
- (NSString *)description;
- (NSString *)XMLString;
- (NSString *)XMLStringWithOptions:(NSUInteger)options;
//- (NSString *)canonicalXMLStringPreservingComments:(BOOL)comments;
- (NSArray *)nodesForXPath:(NSString *)xpath error:(NSError **)error;

- (NSString*)_XMLStringWithOptions:(NSUInteger)options appendingToString:(NSMutableString*)str;
@end

2 个答案:

答案 0 :(得分:2)

SoapService.h可能存在错误,因为错误显示在#import附近。在编译时,预处理器从此文件中获取文本并将其放在此处。有时,.h中的语法错误在找回.m之前无法解决。看看SoapService.h

的末尾

答案 1 :(得分:0)

我认为命名空间是一个保留字。尝试将其更改为其他内容。