No, it is not.
- You pass in
@"" as the starting string. However, @"" is not an NSMutableString. This will certainly produce an exception when run.
- As soon as you
return, then that method stops and you don't execute any more. This means that you go through the first iteration of the loop, you'll stop. Forever.
- You don't return anything if there are no children in the currentNode.
- There's no such method as
appendText:. You probably mean appendString:
Here's another question: Why do you need to return a value at all? You're passing in an NSMutableString and modifying it, so why not just always modify it in place and not bother with a return value? For example:
- (void) parseTree:(Node*)currentNode string:(NSMutableString*)myString {
[myString appendString:currentNode.value];
for(Node * child in [currentNode children]){
[self parseTree:child string:myString];
}
}
And then invoke this with:
NSMutableString * finalString = [NSMutableString string];
[self parseTree:aNode string:finalString];