• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Obtaining an array of the names of the attributes and relations of a class
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Obtaining an array of the names of the attributes and relations of a class


  • Subject: Obtaining an array of the names of the attributes and relations of a class
  • From: Francis Derive <email@hidden>
  • Date: Mon, 21 Nov 2005 16:23:17 +0100

Bonjour !


For example, I have a class which has now 2 instance variables :

@interface MYobject : NSObject {
	NSString *myInstance;
	NSString *myOtherInstance;
	//NSString *_myInstance;
	//NSString *isMyInstance;
}
//- (NSString *) myInstance;
//- (void) setmyInstance:(NSString *) anInstance;
@end

And such a code in the main :

int main (int argc, const char * argv[]) {

MYobject *unObjet = [[MYobject alloc] init];

NSLog(@" what about accessInstanceVariablesDirectly %d", [MYobject accessInstanceVariablesDirectly] ? 1 : 0);
NSLog(@" lecture par kvc de myInstance: -- %@", [unObjet valueForKey:@"myInstance"]);
NSLog(@" lecture par kvc de myOtherInstance: -- %@", [unObjet valueForKey:@"myOtherInstance"]);

[unObjet setValue:@"myInstance with kvc" forKey:@"myInstance"];
[unObjet setValue:@"myOtherInstance with kvc" forKey:@"myOtherInstance"];


NSLog(@" lecture par kvc de myInstance: -- %@", [unObjet valueForKey:@"myInstance"]);
NSLog(@" lecture par kvc de myOtherInstance: -- %@", [unObjet valueForKey:@"myOtherInstance"]);

NSArray *lesAttributs = [[unObjet classDescription] attributeKeys];
NSLog(@" les attributs %@", lesAttributs );
//NSClassDescription *desc = [NSClassDescription classDescriptionForClass:[MYobject class]];
//[registerClassDescription:desc forClass:MYobject];
// insert code here...
NSLog(@"Hello, World!");
[pool release];
return 0;
}


What I get is this : (null)

[Session started at 2005-11-21 16:21:11 +0100.]
2005-11-21 16:21:11.746 KVC[864] what about accessInstanceVariablesDirectly 1
2005-11-21 16:21:11.749 KVC[864] lecture par kvc de myInstance: -- myInstance at init
2005-11-21 16:21:11.750 KVC[864] lecture par kvc de myOtherInstance: -- myOtherInstance at init
2005-11-21 16:21:11.750 KVC[864] lecture par kvc de myInstance: -- myInstance with kvc
2005-11-21 16:21:11.750 KVC[864] lecture par kvc de myOtherInstance: -- myOtherInstance with kvc
2005-11-21 16:21:12.112 KVC[864] les attributs (null)
2005-11-21 16:21:12.113 KVC[864] Hello, World!


KVC has exited with status 0.

So, in the code above I just used the NSObject's instance method "classDescription" which gives a NSClassDescription object, and I know that the application of attributeKeys method on that object should have been "Overriden", but I don't know what to do about that, and so...


Also, I can read in the Key-Value Coding Programming Guide, page 39, that "For example the 'attributes' method return the list of all attributes defined for a class", but this method belongs to the class NSMetaDataItem, which is another worry to get !

I continue searching for the light, but wouldn't wonder if anyone here could give me the light.

Many thanks.

Francis.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Obtaining an array of the names of the attributes and relations of a class
      • From: Scott Anguish <email@hidden>
    • Re: Obtaining an array of the names of the attributes and relations of a class
      • From: John Timmer <email@hidden>
  • Prev by Date: Explicit path for framework
  • Next by Date: NSXML and Character References
  • Previous by thread: Explicit path for framework
  • Next by thread: Re: Obtaining an array of the names of the attributes and relations of a class
  • Index(es):
    • Date
    • Thread