user1526474
user1526474

Reputation: 945

invalid cast type nsmutablearray to type skproduct - ios

I am getting "invalid cast type nsmutablearray to type skproduct" error.. when i try to add the products to my uitableview.. here is the code that i am using...

init

SKProduct *product1 = [[InAppPurchaseManager sharedInAppManager] getLevelUpgradeProduct];
        SKProduct *product2 = [[InAppPurchaseManager sharedInAppManager] getPlayerUpgradeOne];
        SKProduct *product3 = [[InAppPurchaseManager sharedInAppManager] getPlayerUpgradeTwo];

        _products = [[[NSMutableArray alloc] initWithObjects:product1, product2, product3, nil] autorelease];





- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
......
        SKProduct *product = (SKProduct*) _products[indexPath.row]; // error 
        cell.textLabel.text = product.localizedTitle;
        [_priceFormatter setLocale:product.priceLocale];
        cell.detailTextLabel.text = [_priceFormatter stringFromNumber:product.price];

......
}

what is my error? Thanks..

Upvotes: 0

Views: 235

Answers (2)

CodaFi
CodaFi

Reputation: 43330

While I can't replicate it myself, I can infer that the compiler thinks you're trying to cast _products, instead of the object you've accessed from _products. Wrap the entire thing in a set of parenthesis so the compiler knows to evaluate the expression as one piece.

SKProduct *product = (SKProduct*)(_products[indexPath.row]);

Upvotes: 1

Shashank
Shashank

Reputation: 1753

Have you tried

SKProduct *product = (SKProduct *)[_products objectAtIndex:indexPath.row];

Upvotes: 1

Related Questions