Swift function Creation

Source: Internet
Author: User

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 !)

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.