Functions Let's discuss about Functions. To declare a function, use func keyword. Add the parameters and their data type inside a parentheses. The return type is separated by the -> symbol. A general function syntax would be, func ( : ) -> { } func welcome (guest : String, meridian : String) -> String { return "Hello \(guest), \(meridian)." } welcome (name : "Alice", meridian : "Good Morning") Swift supports a great feature when it comes to returning values from functions. You can combine multiple parameters and return them as Tuples . func daysOfWeek(week : [String]) -> (firstDay : String, secondDay : String) { let fristDay : String = week[0] let secondDay : String = week[1] return (firstDay, secondDay) } Here, firstDay and secondDay are two String type parameters that are grouped and returned together. Lets look how the values that are returned and handled in swif...
Comments
Post a Comment