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