Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ip.kban

macrumors newbie
Original poster
Dec 6, 2013
5
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
 
Last edited:
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 :)
 
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> }

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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.