Have a bit of confusion here.
I added a few objects from a class into an array. Now I am trying to iterate through those objects and print them along with all their variables (to console).
NSArray *stockArray=[NSArray arrayWithObjects:stock1, stock2, stock3, nil];
for (int i=0; i<4; i++)
{
StockHolding *stockItem=[[StockHolding alloc]init];
stockItem=[stockArray objectAtIndex:i];
[print stockItem];
}
My Stock Holding class has several properties that I declare in .h and synthesize in .m along with the print method.
However, when I try to use it in the above code to print the “stockItem”, I am getting compiler error “Use of undeclared identifier ‘print'”
This doesn’t make sense since the the Stock Holding class declares print in .h and implements in .m:
-(void) print{
NSLog(@"Current purchase price is %f, current price is %f,
number of shares are %i, cost in dollars is %f, value is dollars is %f",
purchaseSharePrice, currentSharePrice,
numberOfShares, self.costInDollars, self.valueInDollars);
}
Should I be using another way to print these array objects?
Your syntax is backwards. It should be:
Objective-C syntax goes: