标签:冒号 bsp 方法 lips list cap paint class constant
//: Playground - noun: a place where people can play
import UIKit
var str = "Hello, playground"
//var 声明变量 很像JavaScript
var myVariable = 42;
myVariable = 50;
//let 声明常量 JavaScript 的新标准也是用let吧 C++里的const
let myConstant = 42;
let implicitInteger = 70;
let implicitDouble = 70.0;
//显式指定一个常量的类型 用 : (冒号)
let explicitDouble : Double = 70;
let explicitFloat : Float = 4;
let label = "The width is"
let width = 94;
//值永远不会被隐式转换为其他类型。如果你需要把一个值转换成其他类型,请显式转换。 如下,必须把 width 强转为 String才能 和label(String 类型)拼接
let widthLabel = label + String(width);
let apples = 3;
let oranges = 5;
//有一种更简单的把值转换成字符串的方法:把值写到括号中,并且在括号之前写一个反斜杠
let applesSummary = "I have \(apples) apples.";
let fruitSummary = "I have \(apples + oranges) pieces of fruit.";
let mingboHeight = 18.00
let mingbo = " \(mingboHeight)" + " mingbo";
//使用方括号 [] 来创建数组和字典,并使用下标或者键(key)来访问元素。最后一个元素后面允许有个逗号。再也不用担心多写一个逗号了
var shoppingList = ["catfish", "water", "tulips", "blue paint"];
shoppingList[1] = "bottle of water";
var occupations = [
"Malcolm":"Captain",
"Kaylee":"Mechanic",
];
occupations["Jayne"] = "Public Relations";
//要创建一个空数组或者字典,使用初始化语法。
let emptyArray = [String]();
let emptyDictionary = [String :Float]();
//如果类型信息可以被推断出来,你可以用 [] 和 [:] 来创建空数组和空字典——就像你声明变量或者给函数传参 数的时候一样。
shoppingList = [];
occupations = [:];
标签:冒号 bsp 方法 lips list cap paint class constant
原文地址:http://www.cnblogs.com/wjw-blog/p/6067953.html