0

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

#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 字符串包含按顺序连接的 base_url、urlPart2 和 urlPart3。

前任:

base_url = @"www."

urlPart2 = @"我的网站"

urlPart3 = @".com"

网址 = @“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];
4

1 回答 1

1

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

@interface xmlToUrl : NSObject { 

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

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

{[xmlToUrlObject.name addObject:nodeContent];}

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

于 2012-05-01T20:55:05.740 回答