return function result to output argument

user842225

In objective-c I can declare a function with an output argument, I suppose that is so called pass-by-reference:

-(void) doTask(int id, output: (NSArray**)results) {
   …
   results = getResult()
}

Then, I can access the results to check the output of doTask() outside the function scope.

In swift, is it still valid?

func doTask(id:Int, results:NSArray) -> Void {
  …
  results = getResult()
}

Can I pass the end results of doTask() to the function argument results and access it outside the function scope?

Robert

In Swift, you need to mark a parameter as being inout; that is, you can write to it in the function and the changes to the variable take affect outside the function scope:

func doTask(id: Int, inout results: NSArray) -> Void {
    // …

    results = NSArray()
}

Then to call the function, you need to pass a valid variable of that type, and append it with an ampersand:

var results: NSArray()
doTask(4, &results)

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to return the result of a postgresql function in c#? Console output empty

From Dev

PIVOT function with String columns return wrong output result

From Dev

Return argument of mocked method as a result

From Dev

Return the last argument of a function

From Dev

trying to output result of function

From Dev

Return result to parent function

From Dev

Return result of Action to Function

From Dev

Return mongoose result in a function

From Dev

wrapAsync return function not result

From Dev

bind prepared result not return output

From Dev

Why does replace() function return grammatically edited result when it was not requested with proper argument?

From Dev

How to pass the result of a function as argument into a Bash function?

From Dev

function and output foreach result with html

From Dev

Return stored procedure result in function

From Dev

How to get function return result?

From Dev

excel VBA return result of function

From Dev

C - function to return curved result

From Dev

Return select * result in postgres function

From Dev

Creating a function to return boolean result?

From Dev

Where to return result of recursive function

From Dev

Return a array of result from function

From Dev

How to get function return result?

From Dev

Return log output and result object from cmdlet

From Java

Concatenation of the result of a function with a mutable default argument

From Dev

Pass a SELECT result as an argument to postgreSQL function

From Dev

Concatenation of the result of a function with a mutable default argument

From Dev

R- function %in% - different result with the same argument

From Dev

Firebase return output from function

From Dev

Is there any purpose to return the result of a function in an empty function?

Related Related

  1. 1

    How to return the result of a postgresql function in c#? Console output empty

  2. 2

    PIVOT function with String columns return wrong output result

  3. 3

    Return argument of mocked method as a result

  4. 4

    Return the last argument of a function

  5. 5

    trying to output result of function

  6. 6

    Return result to parent function

  7. 7

    Return result of Action to Function

  8. 8

    Return mongoose result in a function

  9. 9

    wrapAsync return function not result

  10. 10

    bind prepared result not return output

  11. 11

    Why does replace() function return grammatically edited result when it was not requested with proper argument?

  12. 12

    How to pass the result of a function as argument into a Bash function?

  13. 13

    function and output foreach result with html

  14. 14

    Return stored procedure result in function

  15. 15

    How to get function return result?

  16. 16

    excel VBA return result of function

  17. 17

    C - function to return curved result

  18. 18

    Return select * result in postgres function

  19. 19

    Creating a function to return boolean result?

  20. 20

    Where to return result of recursive function

  21. 21

    Return a array of result from function

  22. 22

    How to get function return result?

  23. 23

    Return log output and result object from cmdlet

  24. 24

    Concatenation of the result of a function with a mutable default argument

  25. 25

    Pass a SELECT result as an argument to postgreSQL function

  26. 26

    Concatenation of the result of a function with a mutable default argument

  27. 27

    R- function %in% - different result with the same argument

  28. 28

    Firebase return output from function

  29. 29

    Is there any purpose to return the result of a function in an empty function?

HotTag

Archive