xcode debug issue

Discussion in 'Mac Programming' started by ip.kban, Dec 6, 2013.

  1. ip.kban, Dec 6, 2013
    Last edited: Dec 6, 2013

    ip.kban macrumors newbie

    Joined:
    Dec 6, 2013
    #1
    Hello! Something strange is happening with my xcode application. I have following code:
    Code:
      MessageViewer* explorer = [self activeExplorer];
      
    
    I can see the "_viewingPaneController" property of my "explorer" instance in debugger window. And it's not 'nil'. But when I'm trying to get it by using
    Code:
    MessageViewingPaneController *viewingPaneController = [explorer _viewingPaneController];
    i'm getting an error "no known method _viewingPaneController..."

    I tried to use:
    Code:
    - (void *)instanceVariableForKey:(NSString *)aKey instance:(id)_instance;
    {
        if (aKey) {
            Ivar ivar = object_getInstanceVariable(_instance class, [aKey UTF8String], NULL);
            if (ivar) { return (void *)((char *)_instance + ivar_getOffset(ivar)); } }
        return NULL;
    }
    
    ...
    
    MessageViewer* explorer = [self activeExplorer];
    
    MessageViewingPaneController *viewingPaneController = [self instanceVariableForKey:@"_viewingPaneController" instance:explorer];
    
    
    But i'm getting 'nil' in that case.


    I tried to get tall properties of MessageViewer class by using following code:
    Code:
    (id)getIvars:(id)value
    {
        unsigned int varCount;
    
        Ivar *vars = class_copyIvarList([value class], &varCount);
        NSMutableString * str = [[NSMutableString alloc] init];
        for (int i = 0; i < varCount; i++) {
            Ivar var = vars[i];
    
            const char* name = ivar_getName(var);
            const char* typeEncoding = ivar_getTypeEncoding(var);
    
            [str appendFormat:@", %s ,", name];
            // do what you wish with the name and type here
        }
        NSInteger s =0;
    }
    But there is no _viewingPaneController property there. So how it can be possible - i can see this property in the debug window, but this property even doesn't exist in my class? How can i get this property?

    Mac osx version 10.9 mavericks. xcode 5.0.2
     
  2. MacAndor macrumors newbie

    Joined:
    Feb 11, 2012
    #2
    1, [explorer _viewingPaneController] would probably be a private method, but if you can see it in the debug window, that indicates that its some kind of variable. Access of variables (non private) would be explorer->_viewingPaneController

    2, You could use object_getInstanceVariable a bit simpler, the third parameter should be a pointer to the somewhere you want the method to put the actual value into. So something like this should do (only sketch):
    Code:
    void *value = NULL;
    object_getInstanceVariable(_instance class, [aKey UTF8String], &value);
    if (value) { <sometype> realvalue = (<cast>)*vaue; } else { <fail> }
    
    3, You should check the ivars of the superclass separately because class_copyIvarList doesn't give you the ivars of the superclass.

    I don't really know the structure of you classes so for more help I need more info :)
     
  3. MacAndor macrumors newbie

    Joined:
    Feb 11, 2012
    #3
    Forgot to mention few things:
    1, The simpler method would possibly require additional memory management.
    2, Check ivar's value, this could mean, that there isn't any ivar named _viewingPaneController at all.
    3, It could even be a private @property in which case check this: class_copyPropertyList

    https://developer.apple.com/library/mac/documentation/cocoa/reference/objcruntimeref/Reference/reference.html
     

Share This Page