Switch的一个例子: let vegetable = "red pepper" switch vegetable { case "celery": let vegetableComment = "Add some raisins and make ants on a log." case "cucumber", "watercress": let vegetableComment = "Tha…
关于Optional的Control Flow if let constantName = someOptional { statements } 如果该Optional为nil,则不进入if,否则执行且constantName为该Optional的值 例子: if let actualNumber = possibleNumber.toInt() { println("\(possibleNumber) has an integer value of \(actualNumber)"…
Type Aliases typealias AudioSample = UInt16 Booleans 非boolean值不会被替代为bool,例如: let i = 1 if i { // this example will not compile, and will report an error } Tuples 例如:HTTPStatus Code ("404", "Not Found") let http404Error = (404, "No…
let Constant var Variable let implicitInteger = 70 let implicitDouble = 70.0 let explicitDouble: Double = 70 The so-called type implications To include value in strings: let fruitSummary = "I have \(apples + oranges) pieces of fruit." Arrays a…
素材:A Swift Tour 推荐下载Playground:Download Playground objc 自己较为熟悉,想熟悉下风头正劲的 swift.就先从官方的入门手册开始撸. 每一小节,我都摘录或总结3个对自己三观冲击最大的[知识点],以方便以后温习.总结不保证绝对正确,仅供交流之用.O(∩_∩)O哈哈~ Simple Values var 表示变量 let 声明常量 [] 用于声明数组和字符串 Control Flow if 或 while 等的判断条件中必须使用布尔值. 判断条件…
输出函数: print(“hello world!") 无需引入函数库,无须使用“;”作为语句结尾,也无须写跟其它语言一样的main()函数,Swift中,全局区的代码就是程序入口.You don’t need to import a separate library for functionality like input/output or string handling. Code written at global scope is used as the entry point for…