What is a function? :
• A function is a group of statements that defines an action to be performed.
• The main use of a function is to make the code reusable.
Types of Functions:
• Depending on whether a function is predefined or created by programmer; there are two types of function:
• Library functions - Functions that are defined already in Swift Framework.
• User-defined functions - Functions created by the programmer themselves.
Library Functions:
• Library functions are built-in functions that are already defined in Swift framework.
• These functions are present to solve common problems in Swift so that you don't have to solve them yourselves.
• They are simple operations like printing, finding minimum and maximum, etc.
• You can use library function directly by invoking (calling) it.
• If you want, you can see all the functions inside the Swift framework.
• Just write import Swift, press Cmd and Click it. You will navigate to a new page. Search all the statements starting with func
x keyword.
Example 1: Library or Built in Function
print("Hello, World!")
User defined Functions:
• Swift also allows you to define your own function.
• Creating your own function helps to write code to solve problems or perform tasks not available in Swift Framework.
• You can also reuse your function to perform similar tasks in the future.
----------------------------------------------------------------------------------------------------
Thank you - Vikranth Apps