top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration

Facebook Login
Site Registration

How to set multiple return types for function in SWIFT

0 votes
136 views

Is it possible to set multiple return type for function in SWIFT. If yes please provide me syntax .

posted Sep 11, 2014 by Arun

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

You can use multiple return type as sample function below

func count(string: String) -> (vowels: Int, consonants: Int, others: Int) {
    var vowels = 0, consonants = 0, others = 0
    for character in string {
        switch String(character).lowercaseString {
        case "a", "e", "i", "o", "u":
            ++vowels
        case "b", "c", "d", "f", "g", "h", "j", "k", "l", "m",
        "n", "p", "q", "r", "s", "t", "v", "w", "x", "y", "z":
            ++consonants
        default:
            ++others
        }
    }
    return (vowels, consonants, others)
}
answer Sep 22, 2014 by Raju
Similar Questions
0 votes

How to set return type for function in SWIFT.

+1 vote

How to set image for UIImageView in UITableViewCell Asynchronously for each cell.

+1 vote

How to declare single parameter which accept multiple values.

0 votes

I am facing situation to use external parameter name to a function parameter name .. How to achieve this

0 votes

how to use reusable identifier for table view cell in SWIFT.
In Objective C:

static NSString *identifier = @"mainMenuCell";
    cell =[tableView dequeueReusableCellWithIdentifier:identifier];  

Then how it should be in SWIFT

Contact Us
+91 9880187415
sales@queryhome.net
support@queryhome.net
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Bangalore-560102
Karnataka INDIA.
QUERY HOME
...