Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > recursive methods in Objective-C

recursive methods in Objective-C
Thread Tools
arcticmac
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Jul 25, 2005, 11:47 PM
 
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?
     
parallax
Admin Emeritus
Join Date: Oct 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jul 26, 2005, 12:22 AM
 
It'll be easier to debug if you paste your code here
"Against stupidity, the gods themselves contend in vain" (Schiller)
     
Thinine
Mac Elite
Join Date: Jul 2002
Status: Offline
Reply With Quote
Jul 26, 2005, 01:16 AM
 
[self whateverMethod] should work just fine. Perhaps there's something weird with how you're interacting with the variables.
     
arcticmac  (op)
Dedicated MacNNer
Join Date: Apr 2004
Status: Offline
Reply With Quote
Jul 26, 2005, 09:15 AM
 
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..
     
Detrius
Professional Poster
Join Date: Apr 2001
Location: Asheville, NC
Status: Offline
Reply With Quote
Jul 28, 2005, 11:15 PM
 
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 Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 02:15 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,