1

I'm using return EXIT_SUCCESS to exit a void function. However I get a flag that says my method should not return a value.

The code works fine, but is there a better way to exit a method by using a return or something else?

3 Answers 3

7

To add to the other answers, you can always return from a void function with return;

Sign up to request clarification or add additional context in comments.

Comments

6

Redefine the method as

-(int)myMethod; 

Then you can return EXIT_SUCCESS.

Is any code calling this method and expecting a value?

Comments

2

I don't think you understand how functions work. When you specify the prototype asvoid you are saying the function won't return anything. You are then contradicting the prototype by trying to return something. Change the prototype to -(int)function to return EXIT_SUCCESS. If you do not want to return something, but want to still check if it was successful you could pass in a pointer to the function: -(void)functionReturnValue:int* returnValue. Make the function set returnValue to EXIT_SUCCESS on successful completion and have the calling function check returnValue.

2 Comments

You are talking about functions but your examples show methods.
@Till I wasn't aware there was a difference. What's the difference between functions and methods?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.