Learn swift language after summary i

Source: Internet
Author: User


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

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.