Swift Create function

Source: Internet
Author: User


/*
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

Related Article

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.