recursiveDescription


#1

I am getting the message "Undeclared selector “recursiveDescription”, I am using Xcode 6.1 and I think it’s probably due to the book being referring to Xcode 5, I am not satisfied with the current answer, what is the work around or how do use the private method in Xcode 6.1?


#2

That’s just a warning; you should still see the view hierarchy displayed on the console.

Remember, this is just an exercise. If you focus on that aspect of it, particularly given that you’ll never ship code that uses recursiveDescription, you can focus on the part that matters without spending time and energy chasing down this rabbit hole.

But if, like me, sometimes you have bouts of CDO (like Obsessive-Compulsive Disorder – OCD – but with the letters in alphabetical sequence, as they should be! :wink: ), then it is possible to get rid of the warning…but looking at the code, you’ll see why it wasn’t worth the authors’ time.

Modelling after this page, we get:

    SEL recursiveDescriptionSelector = NSSelectorFromString( @"recursiveDescription" );
    IMP recursiveDescriptionImplementation = [self.view methodForSelector: recursiveDescriptionSelector];
    NSString * (*func)(id, SEL) = (void *)recursiveDescriptionImplementation;

    NSLog( @"%@", func( self.view, recursiveDescriptionSelector) );

I don’t pretend to fully understand this – heck, I had never heard of IMP before – and I guessed at recursiveDescription returning a ptr to NSString (at first I just called it an ‘id’), but it does work without generating a warning.


#3

Thanks for the reply, the message “Undeclared selector “recursiveDescription” is misleading, from what I understand from this message is that “recursiveDescription” method though it is private is not declared by the class so when this message is sent to the object associated with it then it is not going to display the view hierarchy, so I thought what it was displaying in the console was the message from some previous NSlog, so from my understanding it was more than a warning and would simply not do what it’s intended to, also for me view Hierarchy is very important as then you can understand what’s associated with what and gives you a better understanding of how your views are connected and also what the different layers underneath are, so this clarification was very important for me and it has nothing to do with OCD. :slight_smile:, and in fact I don’t mind the warning and would stick with the code in book which is simpler
#ifdef VIEW_DEBUG
NSLog(@”%@",[self.window performSelector:@selector(recursiveDescription)]);
#endif