Advertisement
tamerSabek

18032019_2

Mar 18th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.40 KB | None | 0 0
  1. import Foundation
  2.  
  3. enum Direction: CustomStringConvertible{
  4.     case north
  5.     case south
  6.     case east
  7.     case west
  8.  
  9.     var description:String{
  10.         switch self {
  11.             case .north:
  12.                 return "north"
  13.             case .south:
  14.                 return "south"
  15.             case .east:
  16.                 return "east"
  17.             case .west:
  18.                 return "west"
  19.    
  20.         }
  21.     }
  22. }
  23.  
  24. let d:Direction = .north
  25. print (d)
  26.  
  27.  
  28. let d2:Direction = .south
  29. print (d2)
  30.  
  31.  
  32.  
  33.  
  34. enum Element: CustomStringConvertible{
  35.     case fire, water, earth, air
  36.  
  37.     var weakElem:Element{
  38.          switch self {
  39.             case .fire:
  40.                 return .water
  41.             case .water:
  42.                 return .earth
  43.             case .earth:
  44.                 return .air
  45.             case .air:
  46.                 return .fire
  47.          }
  48.     }
  49.  
  50.     var description:String{
  51.          switch self {
  52.             case .fire:
  53.                 return "fire"
  54.             case .water:
  55.                 return "water"
  56.             case .earth:
  57.                 return "earth"
  58.             case .air:
  59.                 return "air"
  60.          }
  61.     }
  62. }
  63.  
  64. let elem:Element = .fire
  65. print(elem)
  66. print(elem.weakElem)
  67.  
  68.  
  69.  
  70. enum Trade{
  71.     case buy(stock:String, amount:Int)
  72.     case sell(stock:String, amount:Int)
  73. }
  74.  
  75. let myTrade:Trade = .buy(stock: "AAPL", amount: 3)
  76.  
  77. print(myTrade)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement