
Swift
wa1065908163
这个作者很懒,什么都没留下…
展开
-
类和对象
//使用 class可以创建一个类。一个属性的声明则是在类里作为常量或变量声明的,除了是在类的上下文中。方法和函数也是这么写的。class Shape { var numberOfSides =0 let area = 40 func simpleDescription() ->String { re原创 2015-06-30 15:22:17 · 307 阅读 · 0 评论 -
自定义委托实现各种算法
func algorithm(num1:Double, num2: Double, sign: Character ) ->Double { var number:Double switch sign { case "+": number = num1 + num2 case "-": numb原创 2015-07-01 19:49:50 · 906 阅读 · 0 评论 -
swift排序算法和数据结构
var arrayNumber: [Int] = [2,4, 6, 7, 3, 8, 1]//冒泡排序func maopao(var array: [Int]) -> [Int] { for var i = 0;i count;i++ { for var j = i;j count;j++ { if原创 2015-07-02 09:03:13 · 829 阅读 · 0 评论 -
接口和扩展
//: Playground - noun: a place where people can playimport UIKit//使用 protocol 来声明一个接口。protocol ExampleProtocol { var simpleDescription:String { get } mutating f原创 2015-07-01 14:18:11 · 436 阅读 · 0 评论 -
Swift继承
//声明一个基类class vehicle { var maxPassenger :Int = 0 var manufacturer :String! func description() ->String { return"max passenger is \(maxPassenger) and m原创 2015-07-01 15:40:29 · 524 阅读 · 0 评论 -
Option可选值(一)
//: Playground - noun: a place where people can playimport Cocoaclass Person { var residence: Residence?//供选连接}class Residence { var rooms = [Room]() var number原创 2015-07-01 15:37:21 · 556 阅读 · 0 评论 -
Option可选值可选值(二)
//: Playground - noun: a place where people can playimport Cocoavar str1 ="供选链接和强制拆包的不同。"class Person { var residence: Residence?//供选连接}class Residence { var ro原创 2015-07-01 15:38:38 · 908 阅读 · 0 评论 -
swfit各种Function表现形式
//: Playground - noun: a place where people can playimport UIKit//多返回值函数func countss(string:String) -> (vowels:Int,consonants: Int,others: Int) { var vowels = 0, consonants原创 2015-07-01 15:34:19 · 582 阅读 · 0 评论 -
dictionary字典
//: Playground - noun: a place where people can playimport UIKitvar str ="字典"//声明一个字典var dic:DictionaryString,String> = ["1001":"1","1002":"2","1003":"3"]var num =dic原创 2015-07-01 15:31:21 · 463 阅读 · 1 评论 -
枚举和结构
//: Playground - noun: a place where people can playimport UIKit//使用 enum 来创建枚举。如同类和其他命名类型,枚举也可以有方法enum Rank:Int { case Ace = 1 case Two, Three, Four, Five, Six,原创 2015-07-01 15:27:02 · 582 阅读 · 0 评论 -
swift流程控制
//: Playground - noun: a place where people can playimport UIKit//使用 if 和 switch 作为条件控制。使用 for-in、 for 、 while 、 do-while 作为循环。小括号不是必须的,但主 体的大括号是必需的。let individualS原创 2015-07-01 15:21:40 · 386 阅读 · 0 评论 -
swift简单的赋值
//: Playground - noun: a place where people can playimport UIKitvar str ="Hello, playground"var myVar =45myVar = 90let myCon =90let implictInteger =70原创 2015-07-01 15:18:13 · 802 阅读 · 0 评论 -
函数和闭包
//: Playground - noun: a place where people can playimport UIKit//使用 func 声明一个函数。调用函数使用他的名字加上小括号中的参数列表。使用 -> 分隔参数的名字和返回值类型。func greet(name:String, day: String) ->String {原创 2015-07-01 15:15:28 · 440 阅读 · 0 评论 -
函数类型
//: Playground - noun: a place where people can playimport UIKit//每一个函数都有特定的函数类型,可以充当参数类型和函数的返回类型。func addTwoInts(a:Int, b: Int) -> Int { return a + b}func multiplyTw原创 2015-07-01 15:08:20 · 406 阅读 · 0 评论 -
反初始化函数
//: Playground - noun: a place where people can playimport UIKit//这里是一个反初始化函数操作的例子。struct Bank { static var coinsInBank = 10_000 static func vendCoins(var numberOfCoinsToVend原创 2015-07-01 14:33:44 · 982 阅读 · 0 评论 -
对数组进行各种操作
//: Playground - noun: a place where people can playimport UIKit//声明、定义数组var numbers = [1,1, 2, 3, 5, 8]var strings = ["ios","android", "java"]//数组长度numbers.cou原创 2015-07-01 14:25:55 · 576 阅读 · 0 评论 -
闭包
//: Playground - noun: a place where people can playimport UIKit//Closures/*在 函数 章节中介绍的全局和嵌套函数实际上也是特殊的闭包,闭包采取如下三种形式之一: .全局函数是一个有名字但不会捕获任何值的闭包 .嵌套函数是一个有名字并可以捕获其封闭函数域内值的闭包原创 2015-07-01 14:23:21 · 415 阅读 · 0 评论 -
一个方法实现加减乘除
func numberArray(num1:Double, num2: Double) -> (Double,Double, Double, Double) { var add = 0.0, subtract = 0.0, multiply =0.0, divide = 0.0 add = num1 + num2原创 2015-07-01 19:07:31 · 1028 阅读 · 1 评论