0

I am new to iPhone development. I am parsing XML data and storing its details in a custom object. I have a product class which has product id, product name, etc and I store this in an object. This object is stored in an NSMutableArray.

I want to display the name of each product in a table row. How can I retrieve a particular object name from the NSMutableArray?

1 Answer 1

2

Your question would be more clear if you put up some code you have now, but here are some ideas...

Product * product = (Product *)[array objectAtIndex:0]; //this gives you the first product in the array

And maybe...

//print out the name of each product
for (Product * product in array)
{
    NSLog(@"%@", product.name);
}
Sign up to request clarification or add additional context in comments.

3 Comments

Note that there’s no need for the (Product *) cast.
Hmm...yea you're right. I think I started doing that because of compiler warnings, but maybe newer compilers don't complain anymore.
You can always assign a value of type id to an Objective-C object variable without a type cast and, conversely, you can always assign an Objective-C object to a variable of type id without a type cast.

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.