附加NSMutableString - 预期“。”在“。”之前令牌错误

时间:2012-05-01 20:26:59

标签: nsmutablearray append nsmutablestring inheritance

我不确定我做错了什么。我在想它,因为NSMutableArray的* name和*字段是在不同的文件中声明的。

#import <Foundation/Foundation.h>

@interface xmlToUrl : NSObject {    

    NSString *base_url;
    NSMutableArray *field;
    NSMutableArray *name;
}
@property(nonatomic,retain)NSString *base_url;
@property(nonatomic, retain)NSMutableArray *field;
@property(nonatomic, retain)NSMutableArray *name;

@end

#import "xmlToUrl.h"

@implementation xmlToUrl
@synthesize base_url;
@synthesize field;
@synthesize name;

-(id) init
{
    self = [super init];
    if (self) {
        field = [[NSMutableArray alloc] init];
        name = [[NSMutableArray alloc] init];
    }
    return self;
}

-(void)dealloc
{
    [base_url release];
    [field release];
    [name release];
    [super dealloc];
}

@end

NSMutableArrays填充在ViewController类中:

//nodeContent is just a NSMutableString being added to the *name and *field NSMutableArrays

if([ending isEqualToString:@"name"]){
        if(![nodeContent isEqualToString:@""])
        {[xmlToUrlObject.name addObject:nodeContent];}
    }
    else if([ending isEqualToString:@"field"]){
        if(![nodeContent isEqualToString:@""])
        {[xmlToUrlObject.field addObject:nodeContent];}

错误=预期'。'在'。'之前令牌。 (在下面代码的第一行)

我想要输出的内容:* url string包含所有按顺序连接的base_url,urlPart2和urlPart3。

例如:

base_url = @“www。”

urlPart2 = @“mywebsite”

urlPart3 = @“。com”

url = @“www.mywebsite.com”

//xmlToUrl is an instance of its own class (.m file)  It contains the *name and *field NSMutableArray
//xmlToUrl.h is inherited in this file

NSMutableString *urlPart2 = [xmlToUrl.name objectAtIndex: 0];
    [xmlToUrl.name removeObjectAtIndex:0];
    NSMutableString *url = [xmlToUrl.base_url stringByAppendingString:urlPart2];

    if([xmlToUrl.field count] != 0)
    {NSMutableString *urlPart3 = [xmlToUrl.field objectAtIndex: 0];
    [xmlToUrl.field removeObjectAtIndex:0}
    url = [url stringByAppendingString:urlPart3];

     [urlPart2 release];
     [urlPart3 release];

1 个答案:

答案 0 :(得分:1)

您正在尝试访问类的属性,而不是实例:

@interface xmlToUrl : NSObject { 

NSMutableString *urlPart2 = [xmlToUrl.name objectAtIndex: 0];

您只能访问xmlToUrl实例上的属性,就像您在以下代码行中一样:

{[xmlToUrlObject.name addObject:nodeContent];}

这里,xmlToUrlObject是一个实例,而不是类。