[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
How to find object variable?
From: |
Stefan Urbanek |
Subject: |
How to find object variable? |
Date: |
Tue, 21 Jun 2005 09:07:31 +0200 |
User-agent: |
Internet Messaging Program (IMP) 3.2.2 |
Hi,
In latest StepTalk update I had a problem finding whether receiver knows about a
variable with a given name. I do not care whether it is a real ivar or not. I
have used following code:
NS_DURING
/* test whether variable is an ivar s*/
obj = [receiver valueForKey:varName];
NSDebugLLog(@"STCompiler", "New name: receiver variable %@",
varName);
[receiverVars addObject:varName];
NS_HANDLER
if([[localException name] isEqualToString:NSUnknownKeyException])
{
NSDebugLLog(@"STCompiler", "New name: extern %@", varName);
/* receiver has no such variable */
[externVars addObject:varName];
}
else
{
[localException raise];
}
NS_ENDHANDLER
Basically, what I do is to try to get a value for given key. If it exists, then
I assume that the receiver has that ivar.
Is there a better and cleaner way of doing that?
Thanks for any hints,
Stefan Urbanek
p.s.: GNUstep has NSUnknownKeyException where Cocoa has NSUndefinedKeyException,
I think that for compatibility reasons we should have the second instead.
--
http://stefan.agentfarms.net
First they ignore you, then they laugh at you, then they fight you, then
you win.
- Mahatma Gandhi
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- How to find object variable?,
Stefan Urbanek <=