Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Foundation
- enum Direction: CustomStringConvertible{
- case north
- case south
- case east
- case west
- var description:String{
- switch self {
- case .north:
- return "north"
- case .south:
- return "south"
- case .east:
- return "east"
- case .west:
- return "west"
- }
- }
- }
- let d:Direction = .north
- print (d)
- let d2:Direction = .south
- print (d2)
- enum Element: CustomStringConvertible{
- case fire, water, earth, air
- var weakElem:Element{
- switch self {
- case .fire:
- return .water
- case .water:
- return .earth
- case .earth:
- return .air
- case .air:
- return .fire
- }
- }
- var description:String{
- switch self {
- case .fire:
- return "fire"
- case .water:
- return "water"
- case .earth:
- return "earth"
- case .air:
- return "air"
- }
- }
- }
- let elem:Element = .fire
- print(elem)
- print(elem.weakElem)
- enum Trade{
- case buy(stock:String, amount:Int)
- case sell(stock:String, amount:Int)
- }
- let myTrade:Trade = .buy(stock: "AAPL", amount: 3)
- print(myTrade)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement