2012-05-01 4 views
1

그래, 내가 xcode를 처음 사용하기는했지만이 문제와 관련된 특정 항목을 찾을 수 없다. 그래서 나는 배열을 선언하고 다음 파일에서 인스턴스화 : 나는 혼란 스러워요 곳NSMutableArray 개체 추가/제거 (상속 된 파일)

//xmlToUrl.h 

#import <Foundation/Foundation.h> 


@interface xmlToUrl : NSObject { 
    NSMutableArray *field; 
    NSMutableArray *name; 
} 
@property(nonatomic, retain)NSMutableArray *field; 
@property(nonatomic, retain)NSMutableArray *name; 

@end 

//xmlToUrl.m 

#import "xmlToUrl.h" 

@implementation xmlToUrl 
@synthesize field; 
@synthesize name; 

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

@end 

그래서이있다. 나는 정확하게 "alloc"또는 "init"하는 방법을 모르거나, xmlToUrl.h를 상속받은 다른 파일에서 추가/제거 작업을 처리하는 방법을 모른다.

다른 파일에있는 코드는 이제 null로 인쇄됩니다. 그 아래 나열된. 내가 도대체 ​​뭘 잘못하고있는 겁니까?!?

//nodeContent is just a NSMutableString 

[xmlToUrlObject.name addObject:nodeContent]; 
     NSLog(@"xml Name = %@", xmlToUrlObject.name); 

     //I omitted all the operational code here but if I NSLog nodeContent it prints the correct values 

[xmlToUrlObject.field addObject:nodeContent]; 
     NSLog(@"xml Field = %@", xmlToUrlObject.field); 

답변

1

당신은 당신이를 통해 xmlToUrl 클래스의 인스턴스를 만들 때마다 당신을 [[xmlToUrl ALLOC을 초기화] 그리고 다음

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

에 비슷하게, 구현 파일에서 init 함수가 필요합니다 두 개의 NSMutableArrays를 이미 초기화 한 클래스의 인스턴스를 갖습니다.

+1

완벽하게 작동했습니다. 고맙습니다!! : D 나는 +1 할 담당자가 충분하지 않지만 누군가이 댓글을 읽는다면 그것을받을 가치가있다! – MrHappyAsthma

관련 문제