我不确定我做错了什么。我在想它是因为 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];