|
|
recursive methods in Objective-C
|
|
|
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
Are we allowed to recurse in objective-c? that is, in the implementation of -(void)someMethod:(int)index; can I call [self someMethod:index+1];?
I need something like this for an app I'm writing, but it doesn't seem to work properly. I have a variable called dx (type is int) inside the method, and every time the debugger stops(in the middle of the method), I printed out a pointer to dx, and it was always the same...
What do I have to do to get recursion to work? define a function or something?
|
|
|
|
|
|
|
|
|
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status:
Offline
|
|
It'll be easier to debug if you paste your code here
|
"Against stupidity, the gods themselves contend in vain" (Schiller)
|
|
|
|
|
|
|
|
Mac Elite
Join Date: Jul 2002
Status:
Offline
|
|
[self whateverMethod] should work just fine. Perhaps there's something weird with how you're interacting with the variables.
|
|
|
|
|
|
|
|
|
Dedicated MacNNer
Join Date: Apr 2004
Status:
Offline
|
|
ah... problem was that I had an if(index=something-1) which was supposed to be index== instead, so it was setting index to the wrong thing, so it would think it was on the highest level of the loop when it wasn't.
Thanks anyway..
|
|
|
|
|
|
|
|
|
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status:
Offline
|
|
Originally Posted by arcticmac
ah... problem was that I had an if(index=something-1) which was supposed to be index== instead, so it was setting index to the wrong thing, so it would think it was on the highest level of the loop when it wasn't.
Thanks anyway..
you could have avoided that frustration by using:
if (something-1 == index) // this would give an error in the compiler if you just used =
or
#define EQ ==
if (index EQ something-1)
|
ACSA 10.4/10.3, ACTC 10.3, ACHDS 10.3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Forum Rules
|
|
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
|
|
|
|
|
|