2

I am unable to return an array from a function call in Swift.

The script is a little bit longer now and little complicated as well, but this is basically what the output from within the function would look like:

func getRecentUpdates()
    {
        var updates = [("test", "hello"),("nice", "one")]

        println(updates) 

       return updates  
    }

println displays the array in the console but with the return, an error says NSArray() is not convertible to ()

1
  • hi user .. you do this thing .. -> to indicate the return value of a function! Commented Sep 27, 2015 at 13:15

2 Answers 2

6

This should work:

func getRecentUpdates()->[(String,String)]
{
    let updates = [("test", "hello"),("nice", "one")]

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

1 Comment

@Mika: You're right, I just felt like copying what they had and modifying it slightly so it would work. I will tweak my answer
0

specter's update for swift 4:

func getRecentUpdates()-> Array<[String]>{
    let updates = [("test", "hello"),("nice", "one")]
    return updates  
}

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.