天天看点

swift在 enum中使用函数

enum Rank: Int{

    case Ace = 1

    case Two,Three, Four, Five, Six, Seven, Eight, Nine, Ten

    func competition()->Int{

        switch self{

        case .Two:

            return 2

        case .Three:

            return 3

        case .Four:

            return 4

        case .Five:

            return 5

        default:

            return self.toRaw();

        }

    }

    case Jack, Queen, King

}

func whitchbiger()->Int{

    var a=Rank.Two.competition()

    var b=Rank.Three.competition()

    if a>b{

     return a

    }

    else{

    return b

    }

}

    var biger = whitchbiger()

    print("比较大的数是\(biger )")