Summary of Swift Basic grammar simple knowledge points

Source: Internet
Author: User

The optional default value for 1.var is

Let is no default value

2. Optional Judgment:

The 1> if let system will define a variable to record him, just use it in {}, or you can make continuous judgments using if

For example: if let on = One,let to = two{}

2> using guard to determine optional options

The variable u defined by the guard let u= URL else{return} can be used outside of {}

3> Note: If let cannot be associated with | |   $$ and other conditions, use where you can use | | &&

4> the benefit of using guard is to omit a layer of nesting

3.switch can be judged for any data type, no longer limited to integers, must be added to the default

4.swift inside the definition string is a struct

5. Calculate the length of the string using Str.characters.count

Calculates the length of a string in the UTF8 format

Str.utf8.count

Calculates the number of bytes under the encoding format

Str.lenthofbyteuseingencodeing (encoded format)

6. Traversing a string

For C in Str.characters

7. Concatenation of strings

Let name:string = "Lao Wang"

Let age = 18

1>let str = "I call" + name + "age" + \ (Ages)

2>let str 1 = "My name \ (name) Age \"

8. Print the specified format:

1>let r1 = String (format: "%02d:%02d:%02d", Arguments:[h,m,s])

2>let r2 = String (format: "02d:%02d:%02d", H,m,s)

9. Interception of strings

Let R1 = Str.substringfromindex ("ss". EndIndex)

Advanced advance (left-to-right integer inverse negative)

Seamless conversion of 10.swift to OC

Str as nsstring, you can use the method inside OC

The 11.swift array can be used to add basic data types.

Let array = [1,3,3,4,5]

12. Dictionary merging can use +, but note that the dictionary is of the same type

13. Define an empty array

Let arr: [nsobject] = [NSObject] ()

14. Merging of dictionaries cannot be used + manual traversal is required to add

No keys are added, some values are replaced

Summary of Swift Basic grammar simple knowledge points

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.