4 ms·
When you say multiple returns do you mean something like generator functions, functions that return some form of tuple like construct, functions with variable r
by rectangletangle 12y ago
When you say multiple returns do you mean something like generator functions, functions that return some form of tuple like construct, functions with variable return types, or something else? I haven't looked into Swift much at all, so I'm curious.
- interpol_p 12y agoTuples are used for multiple returns in swift. So a function definition might look like: () -> (Int, String) (Function that takes no parameters, returns an Int/String tuple) Edit: Tuples can also have named parameters, so something like this is possible: () -> (index: Int, name: String) Then the resulting tuple can be accessed by name: //Where x is a tuple returned from the above function x.index x.name
- josephlord 12y agoAs interpol_p says tuples are available. It is also quite possible to return a function or other closure so a generator function is definitely possible. The return type does have to be defined though so there isn't a way to have a variable return type. I suppose you could return something of "Any" type but would you really want to?