swift 簡介和常量與變數 --- swift 入門

來源:互聯網
上載者:User

標籤:ble   add   ring   gre   技術分享   selector   str   rand   target   

一、思維導圖

二、

代碼

//建立UIView 和按鈕     let views = UIView(frame: CGRect(x:20, y: 20, width: 100, height: 100))//FIXME:改變viewsframe        views.backgroundColor = UIColor.yellow        view.addSubview(views)                //MARK: 建立一個按鈕        let Button2 = UIButton(type: .contactAdd)        Button2.backgroundColor = UIColor.red  //FIXME:sfsl        Button2.frame = views.bounds        views.addSubview(Button2)                //        Button2 .addTarget(self, action: #selector(button2Click), for:)        Button2.addTarget(self, action: #selector(button2Click), for: .touchUpInside)    }    //MARK:-- methods response    func button2Click()  {        print("按鈕單擊")    }
//常量和變數
1 let a = 102 let b:Double = 105.33 // Binary operator ‘+‘ cannot be applied to operands of type ‘Int‘ and ‘Double‘4 print(a+Int(b))5 6 7 var name:String = "Hello Word" //不管是變數還是常量必須初始化,且常量的值不能改變8 name = "我是 Hello Word"9 print(name)
 //分支和三運算 //1 if f        let a = 10                if a > 5 {            print("a>5")        }else{            print("a<5")        }        //2 三目        //        a > 5 ? print("a大") : print("a小")        //或寫成        a > 5 ? print("a大大大") :()

 

swift 簡介和常量與變數 --- swift 入門

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.