Lilz
Lilz

Reputation: 4091

Error : getting an object from an NSMutableArray - objective C

I have the following code:

Product product = [[Product alloc] init];
product.title = tag; 
[allProducts addObject:product];
NSString *pImage = [[NSString alloc] initWithFormat:p.title];

But it is failing to return anything

Can anyone kindly help me please? THanks

Upvotes: 0

Views: 77

Answers (1)

willcodejavaforfood
willcodejavaforfood

Reputation: 44073

Nothing in your code is trying to retrieve anything from a collection.

[allProducts addObject:product];

The line above is used for adding objects. If you are looking to retrieve an object you do:

Product* product = [allProducts objectAtIndex:0];

Look at the documentation for NSArray and NSMutableArray.

--update--

Just noticed you have an error in your code:

Product* product = [[Product alloc] init];

(you left out the *)

Upvotes: 1

Related Questions