Swift # Functions

Source: Internet
Author: User

  Sw I ft Learning

  [1] Swift is a programming language that Apple publishes in WWDC2014 to compose OS X and iOS applications. When designing for Swift. OBJECTIVE-C is the programming language that Apple's operating system uses before it is imported to Swift, in the interest of objective-c coexistence

Swift is a new programming language for iOS and OS X applications, based on C and objective-c, without some of the compatibility constraints of C. Swift uses a secure programming model and adds modern features to make programming easier, more flexible, and more fun. The interface is based on the cocoa and cocoa touch framework, which is popular with the people, and shows the new direction of software development.

================

# function Func
println ("[= = = internal and external parameters = = =]");
MARK: internal and External parameters (plus #)
func Say (MyName name:string, MyAge age:int) {
println ("Hello name=\" \ (name) \ "" + "\ n" + "age=\" \ (age) \ ")
}

Say ("MB", 22)
Say (MyName: "MB", myage:22)

Band #
func Say (#name: String, #age: Int) {
println ("Hello \ (name) \ (age)")
}

Say (name: "MB", age:27)

println ("[===== Interchange Value =====]");
MARK: Exchange inout (take address, swap)
Func swap (inout a:int, InOut b:int)
{
var temp = A;
A = b;
b = temp;
}

var x = 10;
var y = 20;
println ("Before a=\ (x) b=\ (y)");

Swap (&x, &y);
println ("A=\ after Exchange (x) b=\ (y)");

Exchange
Func Swap1 (Var a:int, var b:int)
{
var temp = A;
A = b;
b = temp;
}

var x1 = 10;
var y2 = 20;
println ("before exchanging." + "\ n" + "a=\ (x) b=\ (y)");

SWAP1 (x1, y2);

println ("after exchanging." + "\ n" + "a=\ (x) b=\ (y)");

println ("[===== Interchange Value =====]");

Function Arguments
func Add (arr:array<int>), Int {
var sum:int = 0;

For i in Arr {
sum + = i;
}

return sum;

}

println (Add ([1, 2, 3]));

func Add (#a: int, #arr: int ...) int {
var sum:int = 0;

For I in Arr {
sum + = i;

}

return sum + A;
}

println (Add (7, [1, 2, 3]));

================

Ps:

[ one sentence per day ]

"There's always more to learn, and there is always better ways to does what you've done before."-Donald Ervin Knuth

[ recommended website ]

http://www.cocoachina.com/

================

|-> Copyright (c) Bing Ma.

|--> GitHub: https://github.com/SpongeBob-GitHub

================

Swift # Functions

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.