Swift applies to iOS and OSX, built on OC and C, without the C compatibility limit. Swift uses a secure programming model and is supported by the cocoa and cocoa touch frameworks. Swift supports playgrounds, and you can use the Code preview feature in Xcode to instantly see the results of your code running.
Swift does not require a main function and does not require a trailing semicolon.
Using the Let declaration constants, declare the variables using var. such as: let sex = 0 var = 22
Converts a value to a string such as: 1. Let label = ' the width is ' let width = Widthlabel = label + String (width)
2. Write the value in () and write it in the (). Let people = 3 let Peoplesummary = "I have \ (people)". "
Using [] to create arrays and dictionaries, use subscript and key to access elements.
Use if and switch for conditional operation, use For-in,for,while, and do-while to loop.
Use Func to declare a function, use the name and arguments to invoke the function, and so on to specify the function return value. such as: Func Hello (name:string,day:string)->{
Return "Hello \ (name), today is \ (day)."
}
Hello ("Adomikao", "Monday")
Functions can be nested, and nested functions can access variables of the outer function. Use nested functions to reconstruct complex functions.
A function can be used as a return value for another function, and can be passed as a parameter to another function.
A function is a closure that can be used to create an anonymous closure, use in to split a parameter, and return a type. such as: Numbers.map ({
(Number:int)->int in
Let result = 7*number
Retrun result
})
Use class and class names to create a class such as: Class shape{
var numberofsides = 0
Func simpledescription ()->string{
Return "A shape with \ (numberofsides) sides."
}
}
Use an enum to create an enumeration. Enumerations can contain methods.
Use protocol to declare an interface.
Write a name in <> to create a generic function or type.
Learn swift language after summary i