Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. I got a curious about how compiler determines a value's **rawValue**. First, I give you an example code:
  2.  
  3. enum Rank: Int{
  4. case Tom
  5. case Jane
  6. case Steve, Tim
  7. }
  8.  
  9. In this situation, `Rank.Tom.rawValue` is 0, also `Rank.Jane.rawValue` is equal to 1 (increment as 1). It means, compiler determines **rawValue** automatically starting from 0, **if data type is Int.**
  10.  
  11. Let me give you an another example, I decided another starting **rawValue** point as 5 like below:
  12.  
  13. enum Rank: Int{
  14. case Tom = 5
  15. case Jane
  16. case Steve, Tim
  17. }
  18.  
  19. Then `Rank.Jane.rawValue` is equal to 6. Also, If I set Jane's **rawValue** as 10 (keeping Tom = 5), `Rank.Steve.rawValue` is equal to 11.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement