0
-(void) readRestaurantFromXml {  
    SGAAppDelegate *app = (SGAAppDelegate *)[[UIApplication sharedApplication] delegate];
    NSString *myRequestString = [NSString stringWithFormat:@"%@getXml.aspx",app.SERVER_URL];    
    NSURL *url = [NSURL URLWithString: myRequestString];
    CXMLDocument *rssParser = [[[CXMLDocument alloc] initWithContentsOfURL:url options:0 error:nil] autorelease];
    resultNodes = [rssParser nodesForXPath:@"//item" error:nil];    
    listOfItems = [[NSMutableArray alloc] init];
    for (CXMLElement *resultElement in resultNodes) {
        NSString *theatre_id = [[resultElement childAtIndex:0] stringValue];
        NSString *theatre_name = [[resultElement childAtIndex:1] stringValue];
        NSString *restaurant_id  = [[resultElement childAtIndex:2] stringValue];
        NSString *restaurant_name  = [[resultElement childAtIndex:3] stringValue];
        NSString *restaurant_desc = [[resultElement childAtIndex:4] stringValue];
        NSString *deal_avail = [[resultElement childAtIndex:5] stringValue];
        NSString *deal_details = [[resultElement childAtIndex:6] stringValue];      
        Restaurant *workVal = [[Restaurant alloc] initWithRestTitle:restaurant_name restDesc:restaurant_desc theatreId:theatre_id theatreName:theatre_name restId:restaurant_id restDeals:deal_avail restDealDesc:deal_details];
        [listOfItems addObject:workVal];            
        [workVal release];      
    }

}
-(void)myTask{
   NSLog(@"%d",[listOfItems count]);
}

The NSMutableArray listofItems has 3 values.So how can i extract the array value in another method?

Help me

2 Answers 2

1

Fast enumeration is the preferred method.

for (id object in listOfItems) {
  //Do something...
}

If you want a single object at an index:

id object = [listOfItems objectAtIndex:someIndex];

If you just want an object (expecting the array to have a single object:

id object = [listOfItems lastObject];
Sign up to request clarification or add additional context in comments.

Comments

0
for(int i=0; i < [listOfItems count]; ++i) {
    Restaurant* r = [listofItems objectAtIndex:i];
}

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.