Good day! It is necessary to return the String from this function so that other functions see it! When I use the standard syntax -> String, I swear that I should use Void! Tell me please!

Closed due to the fact that the essence of the question is not clear to the participants of the Denis , pavel , katso , aleksandr barakin , HamSter Nov 1, '16 at 10:00 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • show the entire function signature - Max Mikheyenko
  • in the future, try to write more detailed questions - give the signature of the function and the full text of the error. - Max Mikheyenko

1 answer 1

You cannot return values ​​from the @IBAction functions, because these functions are called by the system, so (1) the system does not need any values ​​as a result of executing these functions (2) if you want to call these functions yourself, then you are doing something wrong.

If the IBAction function contains some code that makes sense to call them from other parts of the program, all of this can be refactored this way:

@IBAction func someAction(_ sender: Any) { self.someActionWithReturn(sender) } func someActionWithReturn(_ sender: Any) -> String { return "123" } 

and if you need to call this function, call someActionWithReturn

  • And how can I pass the value sender.text from someAction to the function someActionWithReturn from someAction if nothing can be transferred from it .... - Igor Ivanov
  • @ IgorIvanov added to the answer - Max Mikheyenko
  • I just need to compare two values ​​from two different IBAction functions that do not return parameters ... How to be ... - Igor Ivanov
  • save them in variables - Max Mikheyenko
  • That's right. But variables are stored inside functions that do not return them ... - Igor Ivanov