为了初始化结构体和类等类型的实例属性。默认构造器[html]view plaincopystructFahrenheit{vartemperature:Doubleinit(){temperature=32.0}}var f = Fahrenheit() //调用默认构造器 init() ,没有参数...
分类:
其他好文 时间:
2014-07-02 22:42:28
阅读次数:
238
Dictionaries (字典) 字典像是一个容器,它可以存放很多相同类型的值.每个值都有与之关联的唯一的键,键在字典里的作用,就像是每个值的身份证标识一样.与数组中的元素不同,字典里的每个元素没有 固定的循序.当你使用字典并且要查询一个值的时候,需要使用值的标识(key)才行.这就像是你在生.....
分类:
移动开发 时间:
2014-07-02 21:55:41
阅读次数:
297
一.常量和变量Swift语言对常量和变量的声明进行了明确的区分使用let关键字声明一个常量:let maxNmber = 18 //声明了一个常量 初始值为18,常量的值是不能够改变的,使用var关键字声明一个变量:var number = 12 //声明了一个变量,初始值为12, 变量的值是可.....
分类:
其他好文 时间:
2014-07-02 21:42:15
阅读次数:
313
在GameViewController.swift中重载prefersStatusBarHidden方法,返回trueoverride func prefersStatusBarHidden() -> Bool { return true}
分类:
其他好文 时间:
2014-07-02 21:12:29
阅读次数:
1108
这不是教程。当你碰到函数参数需要传递一个闭包(closure)时,一般是可以直接这么传递的(假定无返回):// 教程一般教你在参数位置传递closure:someMethod(arg1, arg2, arg3: { args -> Void in //codes here })// sw...
分类:
其他好文 时间:
2014-07-02 18:26:34
阅读次数:
164
1、断言
let age = -3
assert(age >= 0, "A person's age cannot be less than zero")
// 因为 age
2、Swift赋值符(=)不返回值,以防止把想要判断相等运算符(==)的地方写成赋值符导致的错误。数值运算符(+,-,*,/,%等)会检测并不允许值溢出。
3、在对负数b求余时,b的符号会被忽略。这意味着 a %...
分类:
其他好文 时间:
2014-07-02 11:46:51
阅读次数:
286
采用中英文对照的方式,对《The Swift Programming Language》进行翻译...
分类:
编程语言 时间:
2014-07-02 11:42:20
阅读次数:
264
为了初始化结构体和类等类型的实例属性。默认构造器 struct Fahrenheit {var temperature: Doubleinit(){temperature = 32.0} } var f = Fahrenheit() //调用默认构造器 init() ,没有参数 没有返回值。println("The default temperature is \(f.temperature...
分类:
其他好文 时间:
2014-07-02 08:42:57
阅读次数:
304
在现有类和结构体的类型基础上,扩展新的功能。 语法:extension SomeType{// new functionality to add to SomeType goes here}An extension can extend an existing type to make itadopt one or more protocols.Where this is the case,the...
分类:
其他好文 时间:
2014-07-02 07:36:22
阅读次数:
244