码迷,mamicode.com
首页 > 移动开发 > 详细

IOS_Swift_enum枚举方法

时间:2015-12-01 00:12:14      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:

enum Type: Int{
    case A=1
    case B=3
    
    //普通方法
    func toString()->String{
        var info=""
        
        switch self{
        case .A:
            info = "一"
            
        case .B():
            info = "三"
        }
        return info
    }
    
    //静态方法
    static func toString(let type:Type)->String{
        return "toString() -> \(type)"
    }
    
    // 成员
    var description:String{
        var info=""
        switch self{
        case .A:
            info = "一"
            
        case .B():
            info = "三"
        }
        return "description field = \(type)"
    }
}

let type = Type.B

print(Type.toString(type))
print(type.description)

//toString() -> B
//description field = B


IOS_Swift_enum枚举方法

标签:

原文地址:http://blog.csdn.net/zimo2013/article/details/50116811

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!