Swift Basics-Variables

Source: Internet
Author: User

(1) Variables and constants

(2) Basic type

(3) Forced conversion

(4) Type bool

(5) Meta-group

(6) Optional value

  1. Variables and constants
  2. var str = "Hello, Playground"
  3. Let Maxnum = 888
  4. Specify type
  5. var str1:string = "Test"
  6. var int1:int = 1
  7. var dou1:double = 1.
  8. var flo1:float = 1. 111111111111
  9. Forced conversions
  10. var dou2:double = Double (int1) + Dou1
  11. BOOL Type
  12. var bool1:bool = true
  13. BOOL1 = false
  14. if bool1 {
  15. println ("I am true")
  16. } Else {
  17. println ("I am false")
  18. }
  19. Meta-group
  20. var Registionresult = (name:"Name", Age:24,sex:"female")
  21. var Connectionresult = ("404","not found!")
  22. Registionresult. Age
  23. Registionresult. Name
  24. Registionresult. Sex
  25. var registion: (name:string,age:int,sex:string)
  26. Registion. Name = "xxx"
  27. Optional values
  28. var a:int?
  29. A = 12
  30. A = "a". ToInt ()
  31. println ("Age is" + String (a!))

Swift Basics-Variables

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.