Tom
Tom

Reputation: 35

Display NSMutableArray objects as text in UITextView

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

Answers (3)

NeverHopeless
NeverHopeless

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

Mischa
Mischa

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

Julian
Julian

Reputation: 9337

It is because this method removeLastObject do not returns anything, look here. You should get the last object and get the string value add it (append it) to text in text view and the remove if required

Upvotes: 0

Related Questions