🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.next.programmer
Article #291

Re: Getting ids of Outlets of an object

#291
From: Marcel Weiher
Date: Tue, 28 Jul 1992 17:41
68 lines
1954 bytes
vikram@viman.com  (Vikram Duvvoori) writes:


>Hi, 
>	We are interested in developing some general tools that can  
>dynamically access the various outlets of instances of other objects at  
>run-time.
[...]
>Appkit, to determine the tags for the outlets of the instance variables. Are  
>there any methods that give you information on the instance variables and list  
>of methods for an object?

One of the neat things about Objective-C is that it is so dynamic, and yes
it even retains structure information at runtime.

Look in the include file <objc/objc-class.h>, with a little
code to illustrate:

------------------------snip----------------------------
mport <objc/Object.h>
#import <objc/objc-class.h>

@interface Hi : Object
{
	int hi1;
	int hi2;
}

@end

@implementation Hi

-printIVars
{
	Hi*   s1=self;
	struct objc_ivar_list  *iv=s1->isa->ivars;
	struct objc_ivar *p1;
	int i;

	p1=&iv->ivar_list;
	for (i=0; i< iv->ivar_count ; i++ )
	{
		printf( "name= %s, type=%s, offset=%d\n",p1->ivar_name,p1->ivar_type,p1->ivar_offset);
		p1++;
	}
}


main()
{
	id hi=[Hi new];
	[hi printIVars];
}


@end

--------------------------snip----------------------

This produces the following output on my system:

marcel@spock[benchmarks]ivar
name= hi1, type=i, offset=4
name= hi2, type=i, offset=8
marcel@spock[benchmarks]


Marcel
Technical Details
Message-ID: <1992Jul28.174149.15452@cs.tu-berlin.de>
Path: arc1-ca.pugleaf.net!sparky!uunet!paladin.american.edu!europa.asd.contel.com!darwin.sura.net!Sirius.dfn.de!zrz.tu-berlin.de!cs.tu-berlin.de!marcel
References: <1992Jul28.053907.9425@viman.com>

Show Full Headers
Complete Article Headers
Newsgroups: comp.sys.next.programmer
Path: arc1-ca.pugleaf.net!sparky!uunet!paladin.american.edu!europa.asd.contel.com!darwin.sura.net!Sirius.dfn.de!zrz.tu-berlin.de!cs.tu-berlin.de!marcel
From: marcel@opal.cs.tu-berlin.de (Marcel Weiher)
Subject: Re: Getting ids of Outlets of an object
Message-ID: <1992Jul28.174149.15452@cs.tu-berlin.de>
Keywords: outlets, object
Sender: news@cs.tu-berlin.de
Organization: Techn. University of Berlin, Germany
References: <1992Jul28.053907.9425@viman.com>
Distribution: fb20
Date: Tue, 28 Jul 1992 17:41:49 GMT
Lines: 69