Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
XCode enum help
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Nethfel" data-source="post: 1064787" data-attributes="member: 89124"><p>An enum is not a struct. A struct is a structure that would contain variables that would be referenced with a . notation.</p><p></p><p>An enum is simply a listing of values something can take on.</p><p></p><p>in your case, DifficultyLevel can == EASY, but it wouldn't be referenced as DifficutlyLevel.EASY.</p><p></p><p>Honestly the way it is makes much more sense then what you're trying to convert it to.</p><p></p><p>Here's an example, let's say you have a switch statement that will do something based upon variable X</p><p></p><p>switch (x) {</p><p> case 1: .... break;</p><p> case 2: .... break;</p><p> .</p><p> .</p><p> .</p><p> etc.</p><p>}</p><p></p><p>You're testing x to see what it's value is to perform some operation, you're not doing:</p><p></p><p>case x.1 </p><p></p><p>your testing:</p><p></p><p>if (x == 1)</p><p></p><p>it's the same thing with an enum.</p><p></p><p>you're testing</p><p></p><p>if (DifficultyLevel == EASY)</p><p></p><p>Looking at it in the way an if statement would evaluate it sometimes makes it more clear like in this case. EASY is a value that DifficultyLevel can take, EASY is not a part of DifficultyLevel that can be referenced like a variable in a struct.</p></blockquote><p></p>
[QUOTE="Nethfel, post: 1064787, member: 89124"] An enum is not a struct. A struct is a structure that would contain variables that would be referenced with a . notation. An enum is simply a listing of values something can take on. in your case, DifficultyLevel can == EASY, but it wouldn't be referenced as DifficutlyLevel.EASY. Honestly the way it is makes much more sense then what you're trying to convert it to. Here's an example, let's say you have a switch statement that will do something based upon variable X switch (x) { case 1: .... break; case 2: .... break; . . . etc. } You're testing x to see what it's value is to perform some operation, you're not doing: case x.1 your testing: if (x == 1) it's the same thing with an enum. you're testing if (DifficultyLevel == EASY) Looking at it in the way an if statement would evaluate it sometimes makes it more clear like in this case. EASY is a value that DifficultyLevel can take, EASY is not a part of DifficultyLevel that can be referenced like a variable in a struct. [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
XCode enum help
Top