2

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.

3 Answers 3

2

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"]
Sign up to request clarification or add additional context in comments.

1 Comment

you are missing a * after NSString
1

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];

2 Comments

Objective-C does NOT have string concatenation with '+'. This will only create more errors.
You are right. I did not realize that second problem with the code. I updated my reply.
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.