Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I got a curious about how compiler determines a value's **rawValue**. First, I give you an example code:
- enum Rank: Int{
- case Tom
- case Jane
- case Steve, Tim
- }
- 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.**
- Let me give you an another example, I decided another starting **rawValue** point as 5 like below:
- enum Rank: Int{
- case Tom = 5
- case Jane
- case Steve, Tim
- }
- 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