shaNnex
shaNnex

Reputation: 1083

returning an array from a function in Swift

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 ()

Upvotes: 2

Views: 3314

Answers (2)

Native_Mobile_Arch_Dev
Native_Mobile_Arch_Dev

Reputation: 777

specter's update for swift 4:

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

Upvotes: 0

spektr
spektr

Reputation: 777

This should work:

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

   return updates  
}

Upvotes: 6

Related Questions