I have a problem about printing an array. I am a java user, and i am new to objective-c.
in java code, i show u what i want
for(myClass a: myVariable){
System.out.println(a.toString);
}
so how do i do this in objective-c, i have written like this:
- (void) updateTextField:(NSMutableArray *)array{
for (Storage *obj in array) // Storage class holds a name and a price.
[check setText:@"%@",[obj description]]; // i did override the description method to print out the name and price. and "Check" is my textField;
}
it does not work. [check setText:@"%@",obj description]; got error "too many argument to method call if i take out the description;"
here is my Storage.m #import "Storage.h"
@implementation Storage
@synthesize name;
@synthesize price;
- (NSString *)description {
return [NSString stringWithFormat: @"%@ %@", name, price];
}
@end
obj.descriptionor[obj description]. The use of[]for method calls is very disorienting when coming from Java.@"%@"and get something formatted. It needs to be something like[NSString stringWithFormat:@"%@",[obj description]]. (You were the one who wanted to switch from Java.)descriptionmethod shouldn't be used in production code. Great for debugging/logging/learning, though.[check setText:[NSString stringWithFormat:@"%@",[obj description]]];)