Reputation: 35
Hey I am trying to display objects from NSMutableArray
as text in UITextView
and I am getting a problem:
Invalid operands to binary expression ('void' and 'NSString *')
Any suggestions how can it be done?
Here is the Code:
for (id obj in Mview.arrayTape)
viewTape.text = Mview.arrayTape.removeLastObject + @"/n" + viewTape.text;
viewTape is an UITextView , arrayTape is the NSMutableArray passed from another view
Any help would be much appreciated.
Upvotes: 2
Views: 125
Reputation: 11233
removeLastObject
returns nothing (void) and you are appending it result to make a new string:
viewTape.text = Mview.arrayTape.removeLastObject + @"/n" + viewTape.text;
Try this instead: (untested
)
for (NSString* obj in Mview.arrayTape)
{
viewTape.text = [viewTape.text stringByAppendingFormat:@"%@\n", obj];
}
Assuming obj
is a type of NSString
, if it is not use its corresponding string representation.
EDIT
Another approach. not yet offered by other solutions, no need to use for loop
viewTape.text = [Mview.arrayTape componentsJoinedBy:@"\n"]
Upvotes: 2
Reputation: 17231
Mview.arrayTape.removeLastObject
has the return type void
i.e. it does not have a return value. And you cannot concatenate nothing with a string because void
does not have a type (or class).
I guess what you want is this:
viewTape.text = [NSString stringWithFormat:@"%@\n%@",(NSString *)Mview.arrayTape.lastObject,viewTape.text];
You can remove the last object afterwards if intended:
[Mview.arrayTape removeLastObject];
Upvotes: 1