标签:get while apple man number 手工 ott ttl tom
地址:https://itunes.apple.com/cn/book/swift-programming-language/id881256329?mt=11
以下我先说下主要的一些东西,大家都是刚看,所以我也难免会出现理解错误的地方。欢迎指出。当然你也能够直接看官方的文档。
一、let,var基本类型
let:常量,不能二次赋值。赋值时能够不须要指定类型,编译器依据赋值自己主动推断。也能够手工指明类型。
var:变量
let a = 12 // 申明a为常量12,类型Int let b: Double = 12 // 申明a为常量12,手工指定类型Double
let str = "Hello, playground. " let name = "Tom " let count = 10 let say = str + name + String(count) // "Hello, playground. Tom 10"
let a = 1 let b = 2 let say = "the number is \(a + b)" // "the number is 3"
var arr = ["catfish", "water", "tulips", "blue paint"] arr[1] = "bottle of water" // 改动第二项 arr // ["catfish", "bottle of water", "tulips", "blue paint"]
var man = [ "like": "apple", "name": "Tom", ] man["iphone"] = "5s" // 添加字段 man["like"] = "mac" // 改动字段 man // ["iphone": "5s", "like": "mac", "name": "Tom"]
四、控制语句
1、if 不能够直接使用一个变量或者常量来作为条件,必须是推断语句let a = 12 if a > 0 { // do something } else { // do something }
for i in 0..3 { // i = 0, 1, 2 } for var i = 0; i < 3; ++i { // i = 0, 1, 2 } // 数组 let scores = [1, 2, 3, 4, 5] for score in scores { // score } // 字典 let numsDic = [ "a": [2, 3, 5, 7, 11, 13], "b": [1, 1, 2, 3, 5, 8], "c": [1, 4, 9, 16, 25], ] for (key, numbers) in numsDic { for number in numbers { // number } }
var n = 2 while n < 100 { n = n * 2 } var m = 2 do { m = m * 2 } while m < 100
标签:get while apple man number 手工 ott ttl tom
原文地址:http://www.cnblogs.com/brucemengbm/p/6702774.html