CnSwift - 雨燕

agile development - 敏捷开发

Swift学习笔记

Swift学习笔记

  1. 输出:

    print()

  2. 变量

    var a = 1

  3. 常量

    let c = 2

  4. 数据类型

    1
    2
    3
    4
    5
    var str = "Hello "
    var s:String = "World"
    var i:Int = 10
    var words:String = "Hello World"
    print(str)
  5. 字符串连接

    1
    2
    3
    4
    5
    var str = "Hello "
    str = str + "World"
    var i = 100
    str = "\(str),abc,\(i)"
    print(str)
  6. 数组

    1
    2
    var arr = ["Hello", "World", 100, 0.10]
    var arr1 = []
  7. 字典

    1
    2
    3
    4
    var user = ["uid":1, "username":"admin", "password":"123456"]
    user["email"] = "admin@admin.com"
    print(user)
    print(user["email"])
  8. 循环

  9. 流程控制

  10. 函数

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    func sayHello(name:String){
    print("Hello \(name)")
    }
    sayHello("admin")
    func getNums()->(Int, Int){
    return(100, 200)
    }
    let (a, b) = getNums()
    print(a)
    var fun = sayHello
    fun("admin")
  11. 面向对象

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    class Hi{
    func sayHi(){
    print("Hello admin")
    }
    }
    class Hello:Hi{
    var _name:String
    init(name:String) {
    self._name = name
    }
    override func sayHi() {
    print("Hello \(self._name)")
    }
    }
    var hi = Hi()
    hi.sayHi()
    var hello = Hello(name: "admin")
    hello.sayHi()
更多精彩内容,请关注公众号 Golang语言开发栈公众号二维码
感谢赞赏.

Welcome to my other publishing channels