parameters and return types

of functions

Vik Denic
vik denic

--

In objective-c, methods define a return type and parameter type(s). For example, to write a method that prints out “Hello World”, one could write:

This method returns an NSString, and accepts an NSString as a parameter. Calling this method (and assigning it to a string variable) would then look like:

Writing a function in Swift is much more elegant. Simply indicate the function with func followed by its name, parameter type and return type (preceded by -> )

And can simply call it using:

--

--