Swift function Creation
/*
Define functions
*/
// The main body of the sayHello function first defines a new String constant named greeting.
// Add the personName to the setting to form a simple greeting message.
// (PersnalName: String) parameter passing of the Function
// String: Type of the return value of the function. The return arrow (->)
Func sayHello (persnalName: String)-> String
{
Let greeting = Hello + persnalName +!
Return greeting;
}
// Functions without return values
Func sayGoodBye (personNanem: String)
{
Println (Goodbye, (personNanem )!)
}
// The first function printAndCount prints a string and returns its characters of the Int type.
Func printAndCount (stringToPoint: String)-> Int
{
Println (stringToPoint)
Return count (stringToPoint)
}
// The second function, printWithoutCounting, calls the first function, but ignores its return value.
// Call a function
// When the second function is called, the message is printed back by the first function, but the returned value is not used.
Func printWithoutCounting (stringToPonit: String)
{
PrintAndCount (stringToPonit)
}
Func firstSwift (sender: UIButton)
{
Println (Click Event of the first button)
Self. label1.text = button clicked
}
/*
Call a function
*/
Println (sayHello (first function ))
SayGoodBye (first company)
PrintAndCount (Hello world !)
PrintWithoutCounting (hello world !)