Introduction to Swift and constants and variables---Introduction to Swift

Source: Internet
Author: User

First, mind map

Two

Code

//Create UIView and buttonsLet's views = UIView (Frame:cgrect (x:20, y:20, width:100, height:100))//fixme: Change ViewsframeViews.backgroundcolor =uicolor.yellow View.addsubview (views)//MARK: Create a buttonLet Button2 =UIButton (type:. Contactadd) Button2.backgroundcolor= uicolor.red//FIXME:SFSLButton2.frame =views.bounds Views.addsubview (Button2)//Button2. AddTarget (Self, Action: #selector (Button2click), for:)Button2.addtarget (Self, Action: #selector (Button2click), for:. Touchupinside)} //mark:--Methods Responsefunc Button2click () {print ("Button click")    }
//Constants and variables
1Let A =Ten2Let b:double =105.33 //Binary operator ' + ' cannot is applied to operands of type ' Int ' and ' Double '4Print (A +Int (b))5 6 7var name:string ="Hello Word" //either the variable or the constant must be initialized, and the value of the constant cannot be changed8Name ="I am Hello Word"9Print (name)
Branching and//1 if f let        a = ten                if a > 5 {            print ("a>5")        }else{            print ("A<5")        }        // 23 Mesh        /        a > 5 print ("A large"): Print ("a small")        //or write as        a > 5? print ("A large"):()

Introduction to Swift and constants and variables---Introduction to Swift

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.