[IOS] Swift enum and Struct
2015-08-08 10:00
471 查看
// ——————enum——————————
//———————struct——————————–
————-结构体默认带label构造函数——————-
// type 1 enum Direction{ case East case South case West case North } enum Direction2{ case East, South,West, North } var d = Direction.East var d2: Direction = .East d2 = .South // type 2 , Course enum enum Course :Int{ case Android = 1,IOS,WP,Symbian } var c1 = Course.Android let k1 = c1.rawValue let k2 = Course.self.init(rawValue:k1)
//———————struct——————————–
struct Sdemo { var x:Int ; var y:Int ; //Constructor init(){ x = 0; y = 0; } init(x:Int,y:Int){ self.x = x self.y = y } //用"_",这样就不用写 x:和 y:了 init(_ x:Int, _ y:Int){ self.x = x self.y = y } // function is legal func getCenter() -> Int{ return (x+y)/2 } //if you wanna modify the x and y , you should add "mutating" mutating func addOffSet(deltaX:Int ,deltaY:Int)(){ y += deltaY x += deltaX } } var s = Sdemo(x:100,y:100); var s3 = Sdemo(100,100) var s2 = Sdemo() s3.addOffSet(100, deltaY: 200)
————-结构体默认带label构造函数——————-
struct Rect{ var origin :Int; var size :Int; } var rect = Rect(origin : 10, size : 10); //-------------------------------------------------------
相关文章推荐
- iPhone开发入门系列2(iOS8+Swift版)备忘录APP学习01
- Swift学习笔记(二十三)——Swift泛型初识
- Swift学习笔记(二十二)——字典的基本操作
- Swift学习笔记(二十一)——字典
- Swift编程语言学习4.1——周期
- iOS- Swift:如何使用iOS8中的UIAlertController
- swift封装的跑马灯效果
- Swift学习笔记(二十)——数组的基本操作
- [ios] Swift Closure(闭包)
- swift 代码加载xib storyboard
- swift学习笔记
- 【Swift】沙盒缓存
- Ray Wenderlich的swift教程01--推荐资料
- [ios] Swift Basis
- iOS开发实战教学:在Swift怎样创建CocoaPod?
- iPhone开发入门系列1(iOS8+Swift版)天天打靶APP学习15-16
- swift2.0学习之拓展
- swift public、internal和private
- ios开发——swift
- swift2.0学习之类型转换