0

I have 2 model:

@interface Program : NSObject

@property (nonatomic, retain) NSString * name;

@property (nonatomic, strong) NSMutableArray *guides;
@end

@interface Guide : NSObject
@property (nonatomic, retain) NSString *name;
@end

And I add some guides to program from one xml:

    Program *program = [Program new];
    program.name = @"My list"
    for(DDXMLElement *guideElement in [programElement nodesForXPath:@"guide" error:&error])
    {
        Guide *guide = [Guide new];
        guide.name = [guideElement stringValue];// [p attribute:@"name"];
        [program.guides addObject:guide];
        NSLog(@"load guide number: %d", [program.guides count]);
    }

The out is always "load guide number: 0"

2
  • Have you created the NSMutableArray? Such as: self.guides = [NSMutableArray array] Commented Dec 21, 2012 at 3:25
  • Because callling any method of nil object will return nil value. In this case, [program.guides count] will return 0. Commented Dec 21, 2012 at 3:26

2 Answers 2

2

program.guides is nil, since you never created it.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much, it works after I add NSMutableArray *guides = [NSMutableArray new]; and program.guides = guides;
1

In your Program's init method, add:

self.guides = [[NSMutableArray alloc] init];

Or, more sloppily, before your for loop add:

program.guides = [[NSMutableArray alloc] init];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.