/*
Defining functions
*/
The function body of SayHello first defines a new string constant named greeting
and set it up plus personname to make a simple greeting message
(persnalname:string) function's parameter
String: Return value type of function, return arrow (->)
Func SayHello (persnalname:string)->string
{
Let greeting = "Hello" + Persnalname + "!"
return greeting;
}
function with no return value
Func Saygoodbye (personnanem:string)
{
println ("goodbye,\ (personnanem)!")
}
The first function Printandcount, prints a string, and returns its number of characters as an int type
Func Printandcount (stringtopoint:string)->int
{
println (Stringtopoint)
return count (Stringtopoint)
}
The second function printwithoutcounting, calling the first function, but ignoring its return value
Call to function
When the second function is called, the message is printed back by the first function, but the return value is not used
Func printwithoutcounting (stringtoponit:string)
{
Printandcount (Stringtoponit)
}
Func Firstswift (Sender:uibutton)
{
println ("Click event for First button")
Self.label1.text = "button clicked"
}
/*
Calling functions
*/
println (SayHello ("first function"))
Saygoodbye ("first company")
Printandcount ("Hello world!")
Printwithoutcounting ("Hello World!")
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Swift Create function