摘要: Swift 使用来声明泛型函数或泛型类型:1 func repeat(item: ItemType, times: Int) -> ItemType[] {2 var result = ItemType[]()3 for i in 0..times {4 result... 阅读全文
posted @ 2014-06-04 11:33 【Winco】 阅读(575) 评论(0) 推荐(0) 编辑
摘要: 协议 Swift 使用protocol定义协议:1 protocol ExampleProtocol {2 var simpleDescription: String { get }3 mutating func adjust ()4 }类型、枚举和结构都可以实现(adopt)协议... 阅读全文
posted @ 2014-06-04 11:29 【Winco】 阅读(2306) 评论(0) 推荐(0) 编辑
摘要: 枚举 使用enum创建枚举——注意 Swift 的枚举可以关联方法: 1 enum Rank: Int { 2 case Ace = 1 case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten 3 case Jack, Q... 阅读全文
posted @ 2014-06-04 11:24 【Winco】 阅读(581) 评论(0) 推荐(0) 编辑
摘要: 创建和使用类 Swift 使用class创建一个类,类可以包含字段和方法:1 class Shape {2 var numberOfSides = 03 func simpleDescription () -> String {4 return "A shape w... 阅读全文
posted @ 2014-06-04 11:21 【Winco】 阅读(961) 评论(0) 推荐(0) 编辑
摘要: 函数 Swift 使用func关键字声明函数:1 func greet (name: String, day: String) -> String {2 return "Hello \(name), today is \(day)."3 }4 greet ("Bob", "Tuesday"... 阅读全文
posted @ 2014-06-04 11:13 【Winco】 阅读(506) 评论(0) 推荐(0) 编辑
摘要: 概览 Swift 的条件语句包含if和switch,循环语句包含for-in、for、while和do-while,循环/判断条件不需要括号,但循环/判断体(body)必需括号:1 let individualScores = [75, 43, 103, 87, 12]2 var teamScor... 阅读全文
posted @ 2014-06-04 11:09 【Winco】 阅读(213) 评论(0) 推荐(0) 编辑
摘要: Hello, world 类似于脚本语言,下面的代码即是一个完整的 Swift 程序。1 println ("Hello, world")变量与常量 Swift 使用var声明变量,let声明常量。1 var myVariable = 422 myVariable = 503 let myCon... 阅读全文
posted @ 2014-06-04 11:05 【Winco】 阅读(336) 评论(0) 推荐(0) 编辑
摘要: Swift is a new programming language for iOS and OS X apps that builds on the best of C and Objective-C, without the constraints of C compatibility.Swi... 阅读全文
posted @ 2014-06-04 11:01 【Winco】 阅读(309) 评论(0) 推荐(0) 编辑