Simple Function
func showDetails(){
print("GirishCodeAlchemy")
}
showDetails()
Parameters
func ShowMessage(details: String){
print(details)
}
showMessage("GirishCodealchemy")
Multiple values
let days = ["Mon", "Tue", "Wed" , "Thu", "Fri", "Sat", "Sun"]
func printDays(days: [String], appendString: String){
for eachDay in days{
print("\(eachDay + appendString)")
}
}
printDays(days: days, appendString: "day" )
Return values
func sumofTwoNum(first: Int, second: Int) -> String {
return "Sum of two numbers \(first) + \(second) = \( first + second)"
}
let result = sumofTwoNum(first: 3, second: 4)
print(result)
[!IMPORTANT] The parameter of a function is a constant so you won’t be able to change it
[!TIP] Create new variable inside the function to solve the constant issue paramter