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
Objective - c program help (source included)
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="mystic_fm" data-source="post: 772426" data-attributes="member: 28538"><p>You've got a lot of issues in this code that I don't have time to dig through, but I will at least tell you that the undefined variable errors in the earlier version of the code were because your declarations of variables a, b and c were scoped to the first part of the "if" statement. (No, the "else" doesn't make it part of a different function.) Since you also wanted to use the same variables in the "else" part, the most likely approach would have been for you to move the declarations to before the "if" statement (so that you would be using the same variables in both places).</p><p></p><p>In the 2nd version of the code, you've got namespace confusion from using the same variable names (a, b, c) as locals within your "generate" function and also as instance variables of the class object (leading to the "local definition hides instance variable" error you mentioned). This is never a good idea, as can be seen in the "else" portion of your code shown here, where you may think you are assigning values to the locals from the instance variable accessor methods, but in fact you are using the accessor methods to get values for the instance variables and are immediately storing the values right back into the same instance variables they came from (and without using the mutator methods for the latter task).</p><p></p><p>Beyond these fundamental issues, you're also not really on the right track for making a program that responds to a button press to perform additional work. You may want to wait until you have that book in hand before going any further, so that you don't keep going further down the wrong road and accumulating more stuff that you'll only need to unlearn eventually. Or if you don't want to wait, then find some more online Obj-C tutorials and start going through those.</p></blockquote><p></p>
[QUOTE="mystic_fm, post: 772426, member: 28538"] You've got a lot of issues in this code that I don't have time to dig through, but I will at least tell you that the undefined variable errors in the earlier version of the code were because your declarations of variables a, b and c were scoped to the first part of the "if" statement. (No, the "else" doesn't make it part of a different function.) Since you also wanted to use the same variables in the "else" part, the most likely approach would have been for you to move the declarations to before the "if" statement (so that you would be using the same variables in both places). In the 2nd version of the code, you've got namespace confusion from using the same variable names (a, b, c) as locals within your "generate" function and also as instance variables of the class object (leading to the "local definition hides instance variable" error you mentioned). This is never a good idea, as can be seen in the "else" portion of your code shown here, where you may think you are assigning values to the locals from the instance variable accessor methods, but in fact you are using the accessor methods to get values for the instance variables and are immediately storing the values right back into the same instance variables they came from (and without using the mutator methods for the latter task). Beyond these fundamental issues, you're also not really on the right track for making a program that responds to a button press to perform additional work. You may want to wait until you have that book in hand before going any further, so that you don't keep going further down the wrong road and accumulating more stuff that you'll only need to unlearn eventually. Or if you don't want to wait, then find some more online Obj-C tutorials and start going through those. [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
Objective - c program help (source included)
Top