-2

I have return one function:

func abc() -> [Int] {
    return [1,2,3,4]
}

I'm calling this function and trying to modify the return value

abc().sort()

It gives this error:
"Cannot use mutating member on immutable value: 'abc' returns immutable value".

I know in order to change the value inside the function we need to use inout parameter but how to change the value which is returned from the function in swift?

1

1 Answer 1

2

You can only assign the result to a new variable with sorted()

let sortedArray = abc().sorted()
Sign up to request clarification or add additional context in comments.

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.