Since your method is recursive, the return
is returning you to the else
branch of the if
in your loop and continuing the search.
The way it is currently implemented, your method will only ever return the node passed in to it. The only return
statement is return node
, and node
is never modified.
Here is one way you could do it:
+ (INONode *)findByUUID:(NSString*)uuid fromRootNode:(INONode*)node
{
// Check the root node
if ([[node uniqueID] isEqualToString:uuid]) {
return node;
}
// Check each child
for (INONode * childNode in [node children]) {
node = [INONode findByUUID:uuid fromRootNode:childNode];
if (node) {
return node;
}
}
return nil;
}