Advertisement
yanivtamari

enum

Sep 25th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.22 KB | None | 0 0
  1. enum lamp:CustomStringConvertible
  2. {
  3.     case A,B,C,D,E,F
  4.    
  5.     func getValue()->Int{
  6.         let fu:Int=self.hashValue
  7.         switch fu {
  8.         case lamp.A.hashValue:
  9.             return (10)
  10.             case lamp.B.hashValue:
  11.             return (45)
  12.             case lamp.C.hashValue:
  13.             return (75)
  14.             case lamp.D.hashValue:
  15.             return (100)
  16.             case lamp.E.hashValue:
  17.             return (125)
  18.             case lamp.F.hashValue:
  19.             return (150)
  20.         default:
  21.             return (0)
  22.         }
  23.     }
  24.     var description: String{
  25.         let fu:Int=self.hashValue
  26.         switch fu {
  27.             case lamp.A.hashValue:
  28.             return ("you have 25W")
  29.             case lamp.B.hashValue:
  30.             return ("you have 40W")
  31.             case lamp.C.hashValue:
  32.             return ("you have 60W")
  33.             case lamp.D.hashValue:
  34.             return ("you have 75W")
  35.             case lamp.E.hashValue:
  36.             return ("you have 100W")
  37.             case lamp.F.hashValue:
  38.             return ("you have 125W")
  39.         default:
  40.             return ("you dont have lamp....")
  41.         }
  42.     }
  43. }
  44. var myLamp:lamp = .A
  45. print(myLamp)
  46. //print(myLamp.getValue())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement